⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faqs.html

📁 gtk_text program sample&eg
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>  <head>    <title>      Frequently Asked Questions    </title>    <meta name="GENERATOR" content=    "Modular DocBook HTML Stylesheet Version 1.45">    <link rel="HOME" title="GTK+ / Gnome Application Development"    href="ggad.html">    <link rel="UP" title="Appendices" href="appendices.html">    <link rel="PREVIOUS" title="Table of Header Files" href=     "headers.html">    <link rel="NEXT" title="Online Resources" href="online.html">  </head>  <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink=   "#840084" alink="#0000FF">    <div class="NAVHEADER">      <table width="100%" border="0" bgcolor="#ffffff" cellpadding=       "1" cellspacing="0">        <tr>          <th colspan="4" align="center">            <font color="#000000" size="2">GTK+ / Gnome Application            Development</font>          </th>        </tr>        <tr>          <td width="25%" bgcolor="#ffffff" align="left">            <a href="headers.html"><font color="#0000ff" size="2">            <b>&lt;&lt;&lt; Previous</b></font></a>          </td>          <td width="25%" colspan="2" bgcolor="#ffffff" align=           "center">            <font color="#0000ff" size="2"><b><a href="ggad.html">            <font color="#0000ff" size="2"><b>            Home</b></font></a></b></font>          </td>          <td width="25%" bgcolor="#ffffff" align="right">            <a href="online.html"><font color="#0000ff" size="2">            <b>Next &gt;&gt;&gt;</b></font></a>          </td>        </tr>      </table>    </div>    <div class="CHAPTER">      <h1>        <a name="FAQS">Frequently Asked Questions</a>      </h1>      <p>        This chapter contains some commonly-asked questions, and        answers, with references to the rest of the book. See the        table of contents for a summary of the questions.      </p>      <div class="SECT1">        <h1 class="SECT1">          <a name="Z827">Questions, with Answers</a>        </h1>        <div class="SECT2">          <h2 class="SECT2">            <a name="Z828">How do I make my application beep?</a>          </h2>          <p>            Call the <tt class="FUNCTION">gdk_beep()</tt> function.          </p>        </div>        <div class="SECT2">          <h2 class="SECT2">            <a name="Z829">When do I need to destroy my            widgets?</a>          </h2>          <p>            See <a href="z57.html#WIDGETLIFECYCLE">the section            called <i>Widget Life Cycle</i> in the chapter called            <i>GTK+ Basics</i></a> for the simple answer, and <a            href="sec-finalization.html">the section called <i>            Object Finalization</i> in the chapter called <i>The            GTK+ Object and Type System</i></a> for more details.          </p>        </div>        <div class="SECT2">          <h2 class="SECT2">            <a name="Z830">When I turn on memory profiling in glib,            my application becomes unstable. What gives?</a>          </h2>          <p>            Normally <tt class="FUNCTION">g_malloc()</tt> and <tt            class="FUNCTION">g_free()</tt> are just wrappers around            <tt class="FUNCTION">malloc()</tt> and <tt class=             "FUNCTION">free()</tt>, with a couple of extra features            described in <a href="cha-glib.html#GLIB-MEMORY">the            section called <i>Memory</i> in the chapter called <i>            glib: Portability and Utility</i></a>. However, when            you turn on memory profiling, they are no longer            interchangeable with <tt class="FUNCTION">malloc()</tt>            and <tt class="FUNCTION">free()</tt>. So anytime you            incorrectly mix the two pairs of functions, your            program will crash.          </p>          <p>            If you're using the GNU C library, which comes with            nearly all Linux distributions, it has a special            feature which can help you debug this. Set the <tt            class="APPLICATION">MALLOC_CHECK_</tt> environment            variable to <tt class="APPLICATION">2</tt> before            running your program, then run the program in <tt            class="APPLICATION">gdb</tt>. As soon as <tt class=             "FUNCTION">free()</tt> gets a pointer not created by            <tt class="FUNCTION">malloc()</tt>, <tt class=            "FUNCTION">abort()</tt> will be called.          </p>        </div>        <div class="SECT2">          <h2 class="SECT2">            <a name="Z831">To create a custom display, I want to            place widgets in arbitrary locations, or move them            around rapidly, or draw to them directly. How?</a>          </h2>          <p>            You are probably fighting a losing battle. Widgets            really aren't what you want, most likely. Consider            using a <tt class="CLASSNAME">GtkDrawingArea</tt> or            the <tt class="CLASSNAME">GnomeCanvas</tt> to create            your custom display.          </p>          <p>            If you really need interactive widgets, such as a <tt            class="CLASSNAME">GtkEntry</tt> or <tt class=            "CLASSNAME">GtkButton</tt>, you can try to use <tt            class="CLASSNAME">GtkLayout</tt> or <tt class=            "CLASSNAME">GtkFixed</tt>.          </p>          <p>            If you have very specialized needs, you probably need            to write your own widget. <a href="cha-widget.html">the            chapter called <i>Writing a <tt class="CLASSNAME">            GtkWidget</tt></i></a> tells you how to do so.          </p>        </div>        <div class="SECT2">          <h2 class="SECT2">            <a name="Z832">Why does my memory debugging tool show            memory leaks in glib?</a>          </h2>          <p>            glib does not call <tt class="FUNCTION">malloc()</tt>            every time it needs a new node in a data structure. If            it did, building linked lists (for example) would be            substantially slower. Instead, glib caches pools of            equal-sized "memory chunks" for use in these data            structures. Since the chunks are still available for            recycling when your program exits, they are never <tt            class="FUNCTION">free()</tt>d. (Of course, the            operating system will reclaim the memory, but tools            such as <tt class="APPLICATION">ccmalloc</tt> and <tt            class="APPLICATION">Purify</tt> will report it as a            memory leak.)          </p>          <p>            To get around this, you can plug a new <span class=             "STRUCTNAME">GAllocator</span> into most of the data            structures. A <span class="STRUCTNAME">            GAllocator</span> is a pool of memory as described            above. Just create an allocator manually, so you have a            pointer to it; you can then free the allocator when you            are finished. <a href="faqs.html#FL-GLISTALLOCATOR">            Figure 1</a> summarizes the relevant functions for            <span class="STRUCTNAME">GList</span>. A quick glance            through <tt class="FILENAME">glib.h</tt> will reveal            the corresponding functions for other data structures.          </p>          <p>            The <tt class="APPLICATION">name</tt> argument to <tt            class="FUNCTION">g_allocator_new()</tt> is used in            debugging messages; the <tt class="APPLICATION">            n_preallocs</tt> argument is passed through to <tt            class="FUNCTION">g_mem_chunk_new()</tt>.          </p>          <div class="FIGURE">            <a name="FL-GLISTALLOCATOR"></a>            <div class="FUNCSYNOPSIS">              <a name="FL-GLISTALLOCATOR.SYNOPSIS"></a>              <table border="0" bgcolor="#E0E0E0" width="100%">                <tr>                  <td><pre class="FUNCSYNOPSISINFO">#include &lt;glib.h&gt;</pre>                  </td>                </tr>              </table>              <p>                <code><code class="FUNCDEF">void <tt class=                "FUNCTION">                g_list_push_allocator</tt></code>(GAllocator* <tt                class="PARAMETER"><i>allocator</i></tt>);</code>              </p>              <p>                <code><code class="FUNCDEF">void <tt class=                "FUNCTION">                g_list_pop_allocator</tt></code>(void);</code>              </p>              <p>                <code><code class="FUNCDEF">GAllocator* <tt class=                 "FUNCTION">g_allocator_new</tt></code>(gchar* <tt                class="PARAMETER"><i>name</i></tt>, guint <tt                class="PARAMETER"><i>n_preallocs</i></tt>);</code>              </p>              <p>                <code><code class="FUNCDEF">void <tt class=                "FUNCTION">g_allocator_free</tt></code>(GAllocator*                <tt class="PARAMETER"><i>                allocator</i></tt>);</code>              </p>            </div>            <p>              <b>Figure 1. Functions for replacing the <span class=               "STRUCTNAME">GList</span> memory allocator</b>            </p>          </div>        </div>        <div class="SECT2">          <h2 class="SECT2">            <a name="Z833">I get a bunch of "assertion failed"            warnings from GTK+. What causes these?</a>          </h2>          <p>            These come from the <tt class="FUNCTION">            g_return_if_fail()</tt> checks at the beginning of many            GTK+ functions. (They will only appear if your copy of            GTK+ was compiled with debugging turned on---and            hopefully it was if you are writing an application.)            You will need to look at the exact assertion that            failed to see what causes the warning. A common one: if            you accidentally access a destroyed widget or object,            you will have a pointer to memory garbage. Among other            things, this means the type tag will be invalid; so            GTK+'s runtime type checks will fail.          </p>        </div>        <div class="SECT2">          <h2 class="SECT2">            <a name="Z834">Why are some things in Gnome rather than            GTK+?</a>          </h2>          <p>            Historical accident, mostly. Sometimes there is a            reason; for example, GTK+ does not include <tt class=             "APPLICATION">gdk_imlib</tt>, so does not include any            widgets that rely on it. In very general terms, GTK+            imposes less "policy" than Gnome; some Gnome widgets            are deliberately inflexible to keep people from            creating an inconsistent user interface. GTK+ does not            take this approach. Finally, some of the Gnome widgets            were considered too "experimental" to go in GTK+ at the            time. However, the core Gnome widgets discussed in this            book are not in this category.          </p>        </div>        <div class="SECT2">          <h2 class="SECT2">            <a name="Z835">How can I center a window on the            screen?</a>          </h2>          <p>            If the window is a <tt class="CLASSNAME">            GnomeDialog</tt>, this is user-configurable and you            should not do it. In most other cases it would be a bit            strange; but there are exceptions, such as splash            screens. The function you want is <tt class="FUNCTION">            gtk_window_set_position()</tt>; you can leave the            window's position up to the window manager (the            default), ask to have it centered, or ask to have it            appear wherever the mouse pointer is. There is an            enumeration which corresponds to these settings: <span            class="STRUCTNAME">GTK_WIN_POS_NONE</span>, <span            class="STRUCTNAME">GTK_WIN_POS_CENTER</span>, <span            class="STRUCTNAME">GTK_WIN_POS_MOUSE</span>. For            example:          </p>          <table border="0" bgcolor="#E0E0E0" width="100%">            <tr>              <td><pre class="PROGRAMLISTING">&#13;  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);&#13;</pre>              </td>            </tr>          </table>          <p>            You should do this <i class="EMPHASIS">before</i>            calling <tt class="FUNCTION">gtk_widget_show()</tt>,            because the function affects where the window appears            when it is first placed on-screen.          </p>        </div>        <div class="SECT2">          <h2 class="SECT2">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -