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

📄 gtk-faq.sgml

📁 linux下电话本所依赖的一些图形库
💻 SGML
📖 第 1 页 / 共 5 页
字号:
it. There is the GTK+ Tutorial <ulinkurl="http://www.gtk.org/tutorial/">http://www.gtk.org/tutorial/</ulink>, which is undergoingdevelopment. This will introduce you to writing applicationsusing C.</para><para>The GTK+ Tutorial doesn't contain information on all ofthe widgets that are in GTK+. For example code on how to usethe basics of all the GTK+ widgets you should look in thedirectory 'tests' (and associated source files) within the GTK+distribution. Looking at these examples will give you a goodgrounding on what the widgets can do.</para></sect1><!-- ----------------------------------------------------------------- --><sect1><title>How do I use the Glade GUI builder with GTK+? <emphasis>[GTK 2.x]</emphasis></title><para>There are two ways to use Glade. The first way is to useGlade's facilities for generating code; the secondway is to use the libglade library which directly loadsthe XML user interface description files that Gladegenerates into a running program.</para><para>Experienced GTK+ programmers generally strongly recommendusing libglade; you don't have to worry about the interactionbetween Glade generating the source and you editing it,and its been shown to be a method that works betterfor large projects, so there is a lot of example codeout there you can look at.</para><para>An introduction to using libglade can be found in the libglade API docs(<ulink url="http://developer.gnome.org/doc/API/2.0/libglade/libglade-notes.html#libglade-basics">http://developer.gnome.org/doc/API/2.0/libglade/libglade-notes.html#libglade-basics</ulink>).</para></sect1><!-- ----------------------------------------------------------------- --><sect1><title>How do I write security sensitive/SUID/SGID programs with GTK+?Is GTK+ secure? What's this GTK_MODULES security hole I heard about?<emphasis>[GTK 2.x]</emphasis></title><para>The short answer to this question is: you can't, so don't write SUID/SGIDprograms with GTK+</para><para>GTK+ will refuse to run with elevated privileges, as it is not designedto be used in this manner. The only correct way to write a setuid program witha graphical user interface is to have a setuid backend that communicates withthe non-setuid graphical user interface via a mechanism such as a pipe and thatconsiders the input it receives to be untrusted.</para><para>For a more thorough explanation of the GTK+ Developers position onthis issue see <ulinkurl="http://www.gtk.org/setuid.html">http://www.gtk.org/setuid.html</ulink>.</para></sect1><!-- ----------------------------------------------------------------- --><sect1><title>I tried to compile a small <command>Hello World</command> of mine,but it failed. Any clue? <emphasis>[GTK 2.x]</emphasis></title><para>Since you are good at coding, we will not deal withcompile time errors here :)</para><para>The classic command line to compile a GTK+ based program is</para><para><literallayout><literal>gcc -o myprog [c files] `pkg-config gtk+-2.0 --cflags --libs`</literal></literallayout></para><para>You should notice the backquote character which is usedin this command line. A common mistake when you start a GTK+based development is to use quotes instead of backquotes. Ifyou do so, the compiler will complain about an unknown filecalled <filename>pkg-config gtk+-2.0 --cflags --libs</filename>. Thetext in backquotes is an instruction to your shell tosubstitute the output of executing this command into thecommandline.</para><para>The command line above ensures that:</para><itemizedlist><listitem><simpara>the correct C compiler flags will be usedto compile the program (including the complete C headerdirectory list)</simpara></listitem><listitem><simpara>your program will be linked with theneeded libraries.</simpara></listitem></itemizedlist></sect1><!-- ----------------------------------------------------------------- --><sect1><title>What about using the <command>make</command>utility? <emphasis>[GTK 2.x]</emphasis></title><para>This is a sample makefile which compiles a GTK+ basedprogram:</para><programlisting role="C"># basic GTK+ app makefileSOURCES = myprg.c foo.c bar.cOBJS    = ${SOURCES:.c=.o}CFLAGS  = `pkg-config gtk+-2.0 --cflags`LDADD   = `pkg-config gtk+-2.0 --libs`CC      = gccPACKAGE = myprgall : ${OBJS}  ${CC} -o ${PACKAGE} ${OBJS} ${LDADD}.c.o:  ${CC} ${CFLAGS} -c $<# end of file</programlisting><para>For more information about the <command>make</command> utility, youshould read either the related man page or the relevant info file.</para></sect1><!-- ----------------------------------------------------------------- --><sect1><title>I use the backquote stuff in my makefiles, but my makeprocess failed. <emphasis>[GTK 2.x]</emphasis></title><para>The backquote construction seems to not be accepted bysome old <command>make</command> utilities. If you use one of these, themake process will probably fail. In order to have thebackquote syntax working again, you should use the GNU makeutility (get it on the GNU ftp server at <ulinkurl="ftp://ftp.gnu.org/gnu/make/">ftp://ftp.gnu.org/gnu/make/</ulink>).</para></sect1><!-- ----------------------------------------------------------------- --><sect1><title>I want to add some configure stuff, how could I dothis? <emphasis>[GTK 2.x]</emphasis></title><para>To use autoconf/automake, you must first install therelevant packages. These are:</para><itemizedlist spacing=Compact><listitem><simpara>the m4 preprocessor v1.4 or better</simpara></listitem><listitem><simpara>autoconf v2.54 or better</simpara></listitem><listitem><simpara>automake v1.7 or better suggested</simpara></listitem></itemizedlist><para>You'll find these packages on the main GNU ftp server(<ulink url="ftp://ftp.gnu.org/">ftp://ftp.gnu.org/</ulink>)or on any GNU mirror.</para><para>In order to use the powerful autoconf/automake scheme,you must create a configure.in which may look like:</para><programlisting role="C">dnl Process this file with autoconf to produce a configure script.dnl configure.in for a GTK+ based programAC_INIT(myprg.c)AM_INIT_AUTOMAKE(mypkgname, 0.0.1)AM_CONFIG_HEADER(config.h)dnl Checks for programs.AC_PROG_CC dnl check for the c compilerdnl you should add CFLAGS="" here, 'cos it is set to -g by PROG_CCdnl Checks for libraries.AM_PATH_GTK_2_0(2.2.0,,AC_MSG_ERROR(mypkgname 0.1 needs GTK+ 2.2.0))AC_OUTPUT(	Makefile)</programlisting><para>You must add a Makefile.am file:</para><programlisting role="C">bin_PROGRAMS    = myprgmyprg_SOURCES   = myprg.c foo.c bar.cINCLUDES        = @GTK_CFLAGS@LDADD           = @GTK_LIBS@CLEANFILES      = *~DISTCLEANFILES  = .deps/*.P</programlisting><para>If your project contains more than one subdirectory,you'll have to create one Makefile.am in each directory plus amaster Makefile.am which will look like:</para><programlisting role="C">SUBDIRS         = mydir1 mydir2 mydir3</programlisting><para>then, to use these, simply type the followingcommands:</para><programlisting role="C">aclocalautoheaderautoconfautomake --add-missing --include-deps --foreign </programlisting><para>For further information, you should look at the autoconfand the automake documentation (the shipped info files arereally easy to understand, and there are plenty of webresources that deal with autoconf and automake).</para></sect1><!-- ----------------------------------------------------------------- --><sect1><title>I try to debug my GTK+ application with gdb, but ithangs my X server when I hit some breakpoint. AnyIdea? <emphasis>[GTK 2.x]</emphasis></title><para>From Federico Mena Quintero:</para><para><quote>X is not locked up.  It is likely that you are hitting abreakpoint inside a callback that is called from a place in Gtk that hasa mouse grab.</quote></para><para><quote>Run your program with the <literal>--sync</literal>option; it will make it easier to debug. Also, you may want touse the console for running the debugger, and just let theprogram run in another console with the X server.</quote></para><para>Eric Mouw had another solution:</para><para><quote>An old terminal connected to an otherwise unused serialport is also great for debugging X programs. Old vt100/vt220terminals are dirt cheap but a bit hard to get (here in TheNetherlands, YMMV).</quote></para><para>Another option is to run your application on Xnest. Xnest is an X serverwhich displays its root window in a regular window of another X server.  A pointer grab on the Xnest display will not affect the GUI of your debuggerrunning on your regular X server.<programlisting>Xnest :1twm -display :1myapp --display=:1</programlisting></para></sect1></chapter><!-- ***************************************************************** --><chapter><title>Development with GTK+: general questions</title><!-- ----------------------------------------------------------------- --><sect1><title>What widgets are in GTK?</title><para>The GTK+ Tutorial lists the following widgets:</para><programlisting role="C">  GtkObject   +GtkData   | +GtkAdjustment   | `GtkTooltips   `GtkWidget     +GtkContainer     | +GtkBin     | | +GtkAlignment     | | +GtkEventBox     | | +GtkFrame     | | | `GtkAspectFrame     | | +GtkHandleBox     | | +GtkItem     | | | +GtkListItem     | | | +GtkMenuItem     | | | | `GtkCheckMenuItem     | | | |   `GtkRadioMenuItem     | | | `GtkTreeItem     | | +GtkViewport     | | `GtkWindow     | |   +GtkColorSelectionDialog     | |   +GtkDialog     | |   | `GtkInputDialog     | |   `GtkFileSelection     | +GtkBox     | | +GtkButtonBox     | | | +GtkHButtonBox     | | | `GtkVButtonBox     | | +GtkHBox     | | | +GtkCombo     | | | `GtkStatusbar     | | `GtkVBox     | |   +GtkColorSelection     | |   `GtkGammaCurve     | +GtkButton     | | +GtkOptionMenu     | | `GtkToggleButton     | |   `GtkCheckButton     | |     `GtkRadioButton     | +GtkCList     |   `GtkCTree     | +GtkFixed     | +GtkList     | +GtkMenuShell     | | +GtkMenuBar     | | `GtkMenu     | +GtkNotebook     | +GtkPaned     | | +GtkHPaned     | | `GtkVPaned     | +GtkScrolledWindow     | +GtkTable     | +GtkToolbar     | `GtkTree     +GtkDrawingArea     | `GtkCurve     +GtkEditable     | +GtkEntry     | | `GtkSpinButton     | `GtkText     +GtkMisc     | +GtkArrow     | +GtkImage     | +GtkLabel     | | `GtkTipsQuery     | `GtkPixmap     +GtkPreview     +GtkProgressBar     +GtkRange     | +GtkScale     | | +GtkHScale     | | `GtkVScale     | `GtkScrollbar     |   +GtkHScrollbar     |   `GtkVScrollbar     +GtkRuler     | +GtkHRuler     | `GtkVRuler     `GtkSeparator       +GtkHSeparator       `GtkVSeparator</programlisting></sect1><!-- ----------------------------------------------------------------- --><sect1><title>Is GTK+ thread safe? How do I write multi-threaded GTK+applications? <emphasis>[GTK 2.x]</emphasis></title><para>The GLib library can be used in a thread-safe mode bycalling g_thread_init() before making any other GLibcalls. In this mode GLib automatically locks all internaldata structures as needed.  This does not mean that twothreads can simultaneously access, for example, a single hashtable, but they can access two different hash tablessimultaneously. If two different threads need to access thesame hash table, the application is responsible for lockingitself.</para><para>In order to make GDK thread aware, you also need tocall gdk_threads_init() in conjunction with the above call.There is a single globallock that you must acquire with gdk_threads_enter() beforemaking any GDK calls, and release with gdk_threads_leave()afterwards throughout your code.</para><para>A minimal main program for a threaded GTK+ applicationlooks like:</para><programlisting role="C">intmain (int argc, char *argv[]){  GtkWidget *window;  /* init threads */	  g_thread_init(NULL);  gdk_threads_init();    /* init gtk */  gtk_init(&amp;argc, &amp;argv);  window = create_window();  gtk_widget_show(window);  gdk_threads_enter();  gtk_main();  gdk_threads_leave();  return 0;

⌨️ 快捷键说明

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