Search code examples
cgtkgtk3

How can I get GTK to recognize the template I have created?


The repository is here: https://gitlab.com/tristan957/tllt-cp

Compiling the program goes well. I have some unused variables, but that is fine. At run time I am seeing the following warnings, and the GUI that I run is not like the template I have provided.

(tllt-cp:28723): Gtk-CRITICAL **: 22:18:00.249: Unable to load resource for composite template for type 'TlltCpWindow': The resource at “/com/gitlab/tristan957/TlltCp/tllt-cp-window.ui” does not exist

(tllt-cp:28723): Gtk-CRITICAL **: 22:18:00.249: gtk_widget_class_bind_template_child_full: assertion 'widget_class->priv->template != NULL' failed

(tllt-cp:28723): Gtk-CRITICAL **: 22:18:00.249: gtk_widget_class_bind_template_child_full: assertion 'widget_class->priv->template != NULL' failed
Initializing object

(tllt-cp:28723): Gtk-CRITICAL **: 22:18:00.249: gtk_widget_init_template: assertion 'template != NULL' failed

I am not sure what I am missing.


Solution

  • I needed to add the following function

    static void
    tllt_cp_application_startup(GApplication *self)
    {
        g_resources_register(tllt_cp_get_resource());
        g_application_set_resource_base_path(self, "/com/gitlab/tristan957/TlltCp");
    
        G_APPLICATION_CLASS(tllt_cp_application_parent_class)->startup(self);
    }