Assertion 'GTK_IS_WINDOW (window)' failing

I’m running Ubuntu 21.10 with libgtk-4-dev, build-essential and meson installed. I’m working through tutorials at Quickstart Guide and Gtk – 4.0: Getting Started with GTK and getting an error I need help on.

I have a meson.build file:

project(‘project6’, ‘c’)
gtkdep = dependency(‘gtk4’)
glibdep = dependency(‘glib-2.0’)
executable(‘project6’, ‘main.c’, dependencies : [gtkdep, glibdep])

…and a project6.ui from Cambalache that starts with:

<interface>
  <requires lib="gtk" version="4.0"/>
   <object class="GtkWindow" id="window">
     <property name="title">grid</property>
     <child>...

…and a main.c that includes:

 static void
 activate (GtkApplication *app,
           gpointer        user_data)
 {
   /* Construct a GtkBuilder instance and load our UI description */
   GtkBuilder *builder = gtk_builder_new ();
   gtk_builder_add_from_file (builder, "project6.ui", NULL);
 
   /* Connect signal handlers to the constructed widgets. */
   GObject *window = gtk_builder_get_object (builder, "window");
   gtk_window_set_application (GTK_WINDOW (window), app);
 ...

It compiles fine but I get the runtime errors:

 04:21:00 PM  ./project6
 
 (project6:395406): Gtk-CRITICAL **: 16:21:03.623: gtk_window_set_application: assertion 'GTK_IS_WINDOW  window)' failed
 
 (project6:395406): GLib-GObject-WARNING **: 16:21:03.623: invalid (NULL) pointer instance
 
 (project6:395406): GLib-GObject-CRITICAL **: 16:21:03.623: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
 
 (project6:395406): GLib-GObject-WARNING **: 16:21:03.623: invalid (NULL) pointer instance
 
 (project6:395406): GLib-GObject-CRITICAL **: 16:21:03.623: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
 
 (project6:395406): GLib-GObject-WARNING **: 16:21:03.623: invalid (NULL) pointer instance
 
 (project6:395406): GLib-GObject-CRITICAL **: 16:21:03.623: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
 
 (project6:395406): Gtk-CRITICAL **: 16:21:03.623: gtk_widget_show: assertion 'GTK_IS_WIDGET (widget)' failed

Now the odd part - when I started I couldn’t build because <gtk/gtk.h> wasn’t found. I created a symlink from /usr/include/gtk-4.0/gtk to /usr/include/. I did the same with a couple other libs (forget which ones) that suggests to me this could be a setup problem. Any help appreciated.

Turned out to be a simple problem. Meson compiled main.c into project6 inside the builddir folder… but the project6.ui file remained in the root folder. Changing the builder line to this fixed the problem:

gtk_builder_add_from_file (builder, "../project6.ui", NULL);

Of course what you probably actually want to do is embed the file as a gresource

Yes, though I haven’t gotten to that tutorial yet
Slow going. :exploding_head:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.