New to GTK here, I made a basic program which tries to create an empty ApplicationWindow with a menubar as seen here
#include <gtk-3.0/gtk/gtk.h>
#include <assert.h>
void activate(GtkApplication *app) {
GtkBuilder *builder = gtk_builder_new();
assert(gtk_builder_add_from_file(builder, "window.ui", NULL));
assert(gtk_builder_add_from_file(builder, "menu.ui", NULL));
GObject *window = gtk_builder_get_object(builder, "window");
gtk_window_set_application(GTK_WINDOW(window), app);
GObject *menubar = gtk_builder_get_object(builder, "menubar");
gtk_application_set_menubar(app, G_MENU_MODEL(menubar));
}
int main(int argc, char **argv) {
GtkApplication *app = gtk_application_new(NULL,
#ifdef GLIB_VERSION_2_74
G_APPLICATION_DEFAULT_FLAGS
#else
G_APPLICATION_FLAGS_NONE
#endif
);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
g_application_run(G_APPLICATION(app), argc, argv);
}
I’m using an older version of Gio, which is why I have that ifdef but it shouldn’t matter cause I also tried this on an up-to-date machine
window.ui:
<interface>
<object class="GtkApplicationWindow" id="window">
<property name="default-width">600</property>
<property name="default-height">400</property>
<property name="visible">t</property>
</object>
</interface>
menu.ui
<interface>
<menu id="menubar">
<submenu>
<attribute name="label">File</attribute>
<item>
<attribute name="label">Open</attribute>
</item>
</submenu>
</menu>
</interface>
When I do this, the menubar doesn’t show
But, if I remove the <property name="visible">t</property>
line in window.ui and use
gtk_widget_set_visible(GTK_WIDGET(window), TRUE);
at the end of the activate
function instead it works
Why does this happen?