The last time we knew how to use glade, we now use it to do something useful.
First, let's add something in window1 created last time,
The first is a vertical box,
Then there is a label,
Create another horizontal box,
And then two buttons,
Change the location parameters of the button and label, such as label, Border width, padding, width, height, X pad, and y pad,
If you change the name, the parameters called in the following program will change a bit.
Save after feeling good about yourself. Rough
Next, the key part of the comparison is that we have made the appearance, and now we have to deal with it.
Add several signal and save them, for example:
Window1
Count + 1 button
Quit button
Let's add several functions to the original program.
Glade. c
1 # include <Glade/glade. h>
2 # include <GTK/GTK. h>
3
4 static int count;
5
6/* When we click the button, we make Count add one,
7 * and show the answer on the label
8 */
9 void on_button1_clicked (gpointer userdata)
10 {
11 gchar Buf [16];
12 snprintf (BUF, 16, "% d", ++ count );
13
14 printf ("% s/n", Buf );
15 gtk_label_set_label (gtk_label (userdata), Buf );
16}
17
18/* When click the button quit, we wuit */
19 void on_button2_clicked (gtkbutton * button, gpointer userdate)
20 {
21 gtk_main_quit ();
22}
23
24 int main (INT argc, char ** argv)
25 {
26
27 gladexml * window;
28
29 gtk_init (& argc, & argv );
30
31 window = glade_xml_new ("project6.glade", null, null );
32
33 glade_xml_signal_autoconnect (window );
34
35 gtk_main ();
36
37 return 0;
38}
Someone must be surprised that the above two signal functions can be used without function calls.
In the libglade document
The specified function is not referenced anywhere in the program explicitely, but if any signals are defined in the interface description that use "some_signal_handler_func" as the handler name, then this function will automatically be connected.
It can be seen that glade_xml_signal_autoconnect solves this problem.
Next let's repeat the previous steps for compilation.
Gcc-O window glade. c 'pkg-config -- Libs -- cflags libglade-2.0 '-export-dynamic
If the problem is corrected, then./window
Click the button above to test it. Is it OK? Good.
If there is a problem, check your signal settings and adjust the signal function of button1 if necessary.
Good luck