Some instructions here because the porting guide in the Gtk+ docs is quite short at the moment:

Convert the files

gtk_builder_convert <old_glade_file> <new_gtkbuilder_file>

Code changes

  • Remove #include <glade/glade.h>
  • GladeXML* => GtkBuilder*
  • glade_xml_new (FILE, “first_widget”, NULL) becomes

    GError* error = NULL;
    GtkBuilder* builder = gtk_builder_new();
    if (!gtk_builder_add_from_file (builder, FILE, &error)
    g_warning ("Couldn't load builder file: %s", error->message);
  • glade_xml_get_widget (gxml, “widget_name”) becomes GTK_WIDGET (gtk_builder_get_object (builder, “widget_name”))
  • glade_get_widget_name (widget) can be replaced by gtk_widget_get_name(widget)
  • glade_xml_get_widget_prefix (gxml, “prefix”) can be emulated by gtk_builder_get_objects(builder) together with manual filtering. It returns a GSList* instead of a GList* though.

That’s it basically. Don’t forget to adjust your to install the correct files and update!

2 Responses to “Migrate from libglade to GtkBuilder – Quick’n’dirty”

  1. Claessens Xavier Says:

    The biggest work is to GtkBuilder uses GtkUIManager to create menus. All your GtkMenuItem are replaced by GtkAction.

  2. Vadim Says:

    What about Glade being able to save in GtkBuilder format? That’d be quite helpful too 😉

Comments are closed.