The first attempt to use GTK is endless and complicated.CodeJust now, I realized that glade can easily generate a GUI, which is completely separated from the code. Even if you want to modify the interface, you don't need to compile it again, which is indeed very convenient.
There are many tutorials on how to use glade. Let me talk about some difficulties.
Note the following when adding handler to various signal.
First, Handler should be exactly the same as the callback function form of signal, including the function name, parameter type, number of parameters, and return type; this can be found in the GTK User Manual (by the way, the tool devhelp on Ubuntu is very convenient ).
Second, it has also plagued me for a long time: the problem of binding signal and hanlder.
In C code, there are two ways to bind signal and handler:
Gtk_builder_connect_signals and gtk_builder_connect_signals_full.
The former is automatically bound. This function uses a part of gmodule and glib to dynamically load modules to query applications.ProgramSymbol table (function name, variable name, etc.), find the function in the application that can match the callback function name specified in Glade, and connect to the signal. However
Gtk_builder_connect_signals can only work in C. Therefore, if your compiler is g ++, binding is not allowed. I think this is another issue of name mangling (the hateful Microsoft is trying to develop another set of standards to solve so much trouble ......), Therefore, to avoid the trouble, you can force the handler to be called in the form of C, that is, add extern "C" before hangler, and the G ++ test passes in Ubuntu.
The latter is manually bound to singal and hanler. During my trial, I found that no extern "C" is added. What is the difference between the two functions.