libglademm — C++ bindings for libglade


You can compile programs that use the libglademm libraries with the command g++ program-files -o executable-name `pkg-config --cflags --libs libglademm-2.4`.

Note the version number in libglademm-2.4. In contrast to gtk+/gnome, gtkmm/gnomemm have allowed parallel installations of some older and newer versions of the same libraries for Gnome 2. So if you were using libglademm 2.0 or 2.2, then you would use libglademm-2.0 instead of libglademm-2.4 on the compilation line.

Connecting signals

There are two methods of connecting signals in libglademm, both of which are actually part of gtkmm and are thus not specific to libglademm. Both methods are provided through the libsigc++ library, which makes use of the support for signals in the C++ language. This provides two major advantages over the signal connection methods in the C bindings for glib and libglade. First, it means that the signals are typesafe (return type and number and type of arguments are checked), which prevents a number of errors. Second, it means that callback functions can be class member functions. There is also another benefit as well, namely that functions with more arguments than signal handlers are normally allowed to have can be used by making use of the sigc::bind function. However, this is rarely needed since being able to call member functions provides most all flexibility needed. Both methods are discussed below and are demonstrated in the examples.

Because of the strong versatility of the libsigc++ library, and because an equivalent of the glade_xml_signal_autoconnect function would not make much sense (glade_xml_signal_autoconnect requires callback functions to be in the global namespace), equivalents for the libglade-specific connection methods in the C bindings are not provided.

Implicit callback connection

Many predefined signals are already connected for widgets to virtual methods with simple default behavior. For these signals, one can simply override the virtual method in a derived class to handle those signals.

Explicit callback connection

In order to connect callback functions explicitly to a signal, one uses the connect member function of the appropriate signal for the appropriate widget. The only thing that takes a little getting used to is that the callback function must be converted to a sigc::slot before being passed to a connect method. This is done by either calling sigc::ptr_fun (if connecting a callback that is not a member function of some class) or sigc::mem_fun (if connecting a callback that is a member function of some class).

Getting widgets from the parsed .glade file

Getting widgets from the parsed .glade file can be done as follows:

  Gtk::Button* a_button_widget;
  GladeXML_object->get_widget("Button Name", a_button_widget);

However, sometimes we want to create a widget derived from Gtk::Button with the UI specified in the .glade file. In those cases we can use get_widget_derived() as follows:

  DerivedButton* a_button_widget;
  GladeXML_object->get_widget_derived("Button Name", a_button_widget);

Note that this is somewhat different than how it is done in C, because of the desire to use glade to specify the UI for derived types easily as well.