Hi everyone,
I’m learning GTK development with C and I’m trying to figure out how to properly load UI files.
All of the examples I see simply pass the file name (with no path) to gtk_builder_new_from_file
or add_from_file
. This works fine when I compile the application into the same directory as the UI file and run it from there.
However, I’m using GNOME Builder and Meson.
My meson.build file is as follows:
project('example1', 'c')
executable(
meson.project_name(),
sources: [
'main.c',
],
dependencies: [
dependency('gtk+-3.0')
],
install: true
)
install_data('builder.ui')
With this file, I can build and run the application from GNOME Builder. However, it crashes with a Failed to open file “builder.ui”: No such file or directory
message. The only workaround I’ve found is to specify an absolute path instead of a file name, but that doesn’t feel right. Surely, I don’t want absolute paths in my code? Or should I always install the app to /usr/share, even when developing?
Also, I found the following in the GTK Manual:
Other files, such as GtkBuilder ui files, are best loaded from resources stored in the application binary itself. This eliminates the need for most of the files that would traditionally be installed in an application-specific location in
/usr/share
.
But I have no idea how to do this.
So what’s the preferred way of loading UI files in real-world GTK app?