Reputation: 5440
I have this UI file edited with Glade 3.18.3. I open the UI in the (C) gtk program (no problem here, no error messages).
Then I tried to get the widget references out of the builder object using gtk_builder_get_object
, but could not find any.
I read that gtkbuilder used to set the name
attribute of the widgets to the id
, but doesn't do that anymore. So I defined the name
in a couple of widgets, but that didn't help.
In desesperation, I added a simple loop which calls gtk_builder_get_objects
, but this function returns NULL:
GSList *lp, *lst = gtk_builder_get_objects(builder);
printf("%p\n", lst);
for (lp = lst; lp != NULL; lp = lp->next) {
printf("%s\n", (char *)(lp->data));
}
Anyone?
Upvotes: 1
Views: 822
Reputation: 7434
Your example is misleading: you probably have some other problem that your code is not showing.
The following test case uses your very same loop and does not return NULL
. The ui file does not have any name
set on the objects. Try it.
#include <gtk/gtk.h>
int main()
{
GtkBuilder *builder;
GSList *lp, *lst;
gtk_init(NULL, NULL);
builder = gtk_builder_new_from_file("test.ui");
lst = gtk_builder_get_objects(builder);
g_print("%p\n", lst);
for (lp = lst; lp != NULL; lp = lp->next) {
g_print("%p\n", (char *)(lp->data));
}
return 0;
}
And this is test.ui
:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
Upvotes: 1
Reputation: 5440
The problem was that the name
property of the window containing the widgets must also be set in the UI, else the gtk_builder_add_objects_from_file
won't work either.
This is going to be a major headache. The UI is quite complicated (a couple of hundreds of widgets). So that means I have to visit them all in Glade to edit their name
... or maybe write a script. And this worked so well before.
Upvotes: 0