Reputation: 519
I am playing with gtk4 and have the following
static void startapp(GtkApplication *app)
{
GtkWindow *window = (GtkWindow*)gtk_window_new();
gtk_window_set_application(window, app);
gtk_window_set_titlebar(window, gtk_header_bar_new());
gtk_header_bar_set_show_title_buttons(
(GtkHeaderBar*)gtk_window_get_titlebar(window), TRUE);
gtk_window_set_default_widget(window, gtk_button_new_with_label("bar"));
gtk_window_present(window);
}
int main (int response, char **name)
{
GtkApplication *app = gtk_application_new ("org.foo", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", (GCallback)startapp, NULL);
response = g_application_run((GApplication*)app, response, name);
g_object_unref(app);
return response;
}
I dont think it has something to do with the int response
variable. I did create another variable inside the code body and replaced response = ... ; return response
with int foo = ...; return foo
So why isn't the window loading widgets?
Upvotes: 2
Views: 1127
Reputation: 976
In GTK4, you want gtk_window_set_child
to set a child of a window (like GTK3, only one child is allowed).
So you want gtk_window_set_child(window, gtk_button_new_with_label("bar"));
instead of the line gtk_window_set_default_widget(window, gtk_button_new_with_label("bar"));
Upvotes: 3