I have read the documentation for GtkWidget and GtkBuilder, GObject tutorial, GObject Type System Concepts, “Widget Templates” tutorial on GNOME Development website, and source code of gnome-console. I still cannot figure out why a custom widget class I created cannot be used inside a template widget’s ui file.
The specific error I get is
(skipper:48484): Gtk-CRITICAL **: 11:30:00.993: Error building template class 'SkipperWindow' for an instance of type 'SkipperWindow': .:0:0 Invalid object type 'SkipperHeaderBar'
Edit: SkipperHeaderBar can be instantiated and used from inside the init function of SkipperWindow but just not from its .ui file.
By the way, both SkipperWindow and SkipperHeaderBar are template widgets and all source (.c) files (plus resources) are compiled into a single executable file.
Every project needs to do this, since it’s fundamentally how the type system and GtkBuilder work. Some language bindings might do the type registration behind the scenes, but it has to happen.
It is only done “automatically” for types provided by GTK and by libadwaita, or any library that has an initialisation function and that registers types in that function.
I just checked, and gnome-console definitely calls g_type_ensure():