gtk-question-index.html
来自「最新gtk中文资料集」· HTML 代码 · 共 1,276 行 · 第 1/4 页
HTML
1,276 行
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Common Questions</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GTK+ Reference Manual"><link rel="up" href="gtk.html" title="Part I. GTK+ Overview"><link rel="prev" href="gtk-resources.html" title="Mailing lists and bug reports"><link rel="next" href="gtkbase.html" title="Part II. GTK+ Core Reference"><meta name="generator" content="GTK-Doc V1.9 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="part" href="gtk.html" title="Part I. GTK+ Overview"><link rel="part" href="gtkbase.html" title="Part II. GTK+ Core Reference"><link rel="part" href="gtkobjects.html" title="Part III. GTK+ Widgets and Objects"><link rel="chapter" href="ch01.html" title="Object Hierarchy"><link rel="chapter" href="ch02.html" title="Widget Gallery"><link rel="chapter" href="WindowWidgets.html" title="Windows"><link rel="chapter" href="DisplayWidgets.html" title="Display Widgets"><link rel="chapter" href="ButtonWidgets.html" title="Buttons and Toggles"><link rel="chapter" href="NumericEntry.html" title="Numeric/Text Data Entry"><link rel="chapter" href="TextWidgetObjects.html" title="Multiline Text Editor"><link rel="chapter" href="TreeWidgetObjects.html" title="Tree, List and Icon Grid Widgets"><link rel="chapter" href="MenusAndCombos.html" title="Menus, Combo Box, Toolbar"><link rel="chapter" href="Actions.html" title="Action-based menus and toolbars"><link rel="chapter" href="SelectorWidgets.html" title="Selectors (File/Font/Color/Input Devices)"><link rel="chapter" href="LayoutContainers.html" title="Layout Containers"><link rel="chapter" href="Ornaments.html" title="Ornaments"><link rel="chapter" href="ScrollingWidgets.html" title="Scrolling"><link rel="chapter" href="Printing.html" title="Printing"><link rel="chapter" href="MiscObjects.html" title="Miscellaneous"><link rel="chapter" href="AbstractObjects.html" title="Abstract Base Classes"><link rel="chapter" href="PlugSocket.html" title="Cross-process Embedding"><link rel="chapter" href="SpecialObjects.html" title="Special-purpose features"><link rel="chapter" href="RecentDocuments.html" title="Recently Used Documents"><link rel="chapter" href="Builder.html" title="Interface builder"><link rel="chapter" href="DeprecatedObjects.html" title="Deprecated"><link rel="part" href="migrating.html" title="Part IV. Migrating from Previous Versions of GTK+"><link rel="chapter" href="gtk-migrating-checklist.html" title="Migration Checklist"><link rel="chapter" href="gtk-migrating-GtkFileChooser.html" title="Migrating from GtkFileSelection to GtkFileChooser"><link rel="chapter" href="gtk-migrating-GtkAction.html" title="Migrating from old menu and toolbar systems to GtkAction"><link rel="chapter" href="gtk-migrating-GtkComboBox.html" title="Migrating from GtkOptionMenu and GtkCombo to GtkComboBox and GtkComboBoxEntry"><link rel="chapter" href="gtk-migrating-GtkIconView.html" title="Migrating from GnomeIconList to GtkIconView"><link rel="chapter" href="gtk-migrating-GtkAboutDialog.html" title="Migrating from GnomeAbout to GtkAboutDialog"><link rel="chapter" href="gtk-migrating-GtkColorButton.html" title="Migrating from GnomeColorPicker to GtkColorButton"><link rel="chapter" href="gtk-migrating-GtkAssistant.html" title="Migrating from GnomeDruid to GtkAssistant"><link rel="chapter" href="gtk-migrating-GtkRecentChooser.html" title="Migrating from EggRecent to GtkRecentChooser"><link rel="chapter" href="gtk-migrating-GtkLinkButton.html" title="Migrating from GnomeHRef to GtkLinkButton"><link rel="chapter" href="gtk-migrating-GtkBuilder.html" title="Migrating from libglade to GtkBuilder"><link rel="chapter" href="gtk-migrating-tooltips.html" title="Migrating from GtkTooltips to GtkTooltip"><link rel="part" href="pt05.html" title="Part V. GTK+ Tools"><link rel="glossary" href="glossary.html" title="Glossary"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"><link rel="index" href="ix06.html" title="Index of new symbols in 2.8"><link rel="index" href="ix07.html" title="Index of new symbols in 2.10"><link rel="index" href="ix08.html" title="Index of new symbols in 2.12"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="gtk-resources.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="gtk.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GTK+ Reference Manual</th><td><a accesskey="n" href="gtkbase.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="gtk-question-index"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><span class="refentrytitle">Common Questions</span></h2><p>Common Questions — Find answers to common questions in the GTK+ manual</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsect1" lang="en"><a name="id3135803"></a><h2>Questions and Answers</h2><p>This is an "index" of the reference manual organized by common "How doI..." questions. If you aren't sure which documentation to read forthe question you have, this list is a good place to start.</p><div class="qandaset"><table border="0" summary="Q and A Set"><col align="left" width="1%"><tbody><tr class="qandadiv"><td align="left" valign="top" colspan="2"><h5 class="title"><a name="id3135817"></a>1. General</h5></td></tr><tr class="question"><td align="left" valign="top"><a name="id3136565"></a><a name="id3136567"></a><p><b>1.1.</b></p></td><td align="left" valign="top"><p>How do I get started with GTK+?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>The GTK+ <a class="ulink" href="http://www.gtk.org" target="_top">website</a> offers a <a class="ulink" href="http://www.gtk.org/tutorial" target="_top">tutorial</a> and a <a class="ulink" href="http://www.gtk.org/faq" target="_top">FAQ</a>. More documentation rangingfrom whitepapers to online books can be found at the<a class="ulink" href="http://developer.gnome.org/doc" target="_top">GNOME developer's site</a>.After studying these materials you should be well prepared to come back tothis reference manual for details.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3136602"></a><a name="id3136604"></a><p><b>1.2.</b></p></td><td align="left" valign="top"><p>Where can I get help with GTK+, submit a bug report, or make a feature request?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>See the <a class="link" href="gtk-resources.html" title="Mailing lists and bug reports">documentation on this topic</a>.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3136622"></a><a name="id3136624"></a><p><b>1.3.</b></p></td><td align="left" valign="top"><p>How do I port from one GTK+ version to another?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>See the <a class="link" href="gtk-changes-2-0.html" title="Changes from 1.2 to 2.0">list of incompatible changesfrom 1.2 to 2.0</a>. Also, the <a class="ulink" href="http://developer.gnome.org/dotplan/porting/" target="_top">GNOME 2.0 portingguide</a> on <a class="ulink" href="http://developer.gnome.org" target="_top">http://developer.gnome.org</a>has some more detailed discussion of porting from 1.2 to 2.0.You may also find useful information in the documentation for specific widgets and functions.</p><p>If you have a question not covered in the manual, feel free toask on the mailing lists and please <a class="ulink" href="http://bugzilla.gnome.org" target="_top">file a bug report</a> against thedocumentation.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3136668"></a><a name="id3136670"></a><p><b>1.4.</b></p></td><td align="left" valign="top"><p>How does memory management work in GTK+? Should I free data returnedfrom functions?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>See the documentation for <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject"><span class="type">GObject</span></a> and <a class="link" href="GtkObject.html" title="GtkObject"><span class="type">GtkObject</span></a>. For <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject"><span class="type">GObject</span></a> note specifically <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#g-object-ref"><code class="function">g_object_ref()</code></a> and <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#g-object-unref"><code class="function">g_object_unref()</code></a>. <a class="link" href="GtkObject.html" title="GtkObject"><span class="type">GtkObject</span></a> is a subclass of <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject"><span class="type">GObject</span></a> so the same points apply, except that it has a "floating" state (explained in its documentation).</p><p>For strings returned from functions, they will be declared "const" (using <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#G-CONST-RETURN:CAPS"><span class="type">G_CONST_RETURN</span></a>) if they should not be freed. Non-const strings should be freed with <ahref="/usr/share/gtk-doc/html/glib/glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a>. Arrays follow the same rule. (If you find an exception to the rules, please report a bug to <a class="ulink" href="http://bugzilla.gnome.org" target="_top">http://bugzilla.gnome.org</a>.)</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3136761"></a><a name="id3136763"></a><p><b>1.5.</b></p></td><td align="left" valign="top"><p>Why does my program leak memory, if I destroy a widget immediately after creating it ?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>If <span class="structname">GtkFoo</span> isn't a toplevel window, then</p><div class="informalexample"><pre class="programlisting"> foo = gtk_foo_new (); gtk_widget_destroy (foo);</pre></div><p>is a memory leak, because no one assumed the initial floating reference. If you are using a widget and you aren't immediately packing it into a container, then you probably want standard reference counting, not floating reference counting.</p><p>To to get this, you must acquire a reference to the widget and drop the floating reference (“<span class="quote">ref and sink</span>” in GTK+ parlance) after creating it:</p><div class="informalexample"><pre class="programlisting"> foo = gtk_foo_new (); g_object_ref (foo); gtk_object_sink (GTK_OBJECT (foo));</pre></div><p>When you want to get rid of the widget, you must call <a class="link" href="GtkWidget.html#gtk-widget-destroy"><code class="function">gtk_widget_destroy()</code></a>to break any external connections to the widget before dropping your reference:</p><div class="informalexample"><pre class="programlisting"> gtk_widget_destroy (foo); g_object_unref (foo); </pre></div><p>When you immediately add a widget to a container, it takes care ofassuming the initial floating reference and you don't have to worryabout reference counting at all ... just call <a class="link" href="GtkWidget.html#gtk-widget-destroy"><code class="function">gtk_widget_destroy()</code></a>to get rid of the widget.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3136844"></a><a name="id3136846"></a><p><b>1.6.</b></p></td><td align="left" valign="top"><p>How do I use GTK+ with threads?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>This is covered in the <ahref="/usr/share/gtk-doc/html/gdk/gdk-Threads.html">GDK threads documentation</a>. See also the <ahref="/usr/share/gtk-doc/html/glib/glib-Threads.html">GThread</a> documentation for portable threading primitives.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3136870"></a><a name="id3136872"></a><p><b>1.7.</b></p></td><td align="left" valign="top"><p>How do I internationalize a GTK+ program?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>Most people use <a class="ulink" href="http://www.gnu.org/software/gettext/" target="_top">GNUgettext</a>, already required in order to install GLib. On a UNIXor Linux system with gettext installed, type <code class="literal">info gettext</code> to read the documentation.</p><p>The short checklist on how to use gettext is: call <code class="function">bindtextdomain()</code> so gettext can find the files containing your translations, call <code class="function">textdomain()</code> to set the default translation domain, then call <code class="function">gettext()</code> to look up each string to be translated in the default domain. Conventionally, people define macros asfollows for convenience:</p><div class="informalexample"><pre class="programlisting"> #define _(x) gettext (x) #define N_(x) x</pre></div><p>You use <ahref="/usr/share/gtk-doc/html/glib/glib-I18N.html#N-:CAPS"><code class="function">N_()</code></a> (N stands for no-op) to mark a string for translation in a context where a function call to <code class="function">gettext()</code> is not allowed, such as in an array initializer. You eventually have to call <code class="function">gettext()</code> on the string to actually fetch thetranslation. <code class="function">_()</code> both marks the string for translation and actually translates it.</p><p>Nowadays, GLib provides the common shorthand macros in the header file<code class="filename">gi18n.h</code>, so you don't have to define them yourself, just include that header.</p><p>Code using these macros ends up looking like this:</p><div class="informalexample"><pre class="programlisting"> #include <gi18n.h> static const char *global_variable = N_("Translate this string"); static void make_widgets (void) { GtkWidget *label1;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?