Search code examples
cgtkbinaryfiles

How to embed `.ui` file on a binary gtk application?


I'm working on a GTK application that loads a .ui file from a relative path but the compiled binary file is not able to find the interface file later.

What's the common way of dealing with .ui files? Is there a way to "embed" the .ui file within the binary distribution?


Solution

  • This is up to you, but I can name two "standard" ways of doing so:

    The first is to require your .ui files to be externally installed in something like /usr/share/[your program name here]/ or similar. This is probably not what you want to do (and I would personally not recommend this, but that's just my opinion...).

    The other way is to use a GResource file. GResource is part of GLib, which GTK+ is built on top of. Everything you need to know is listed on that page, under "Description". (This is the method I would prefer using, at least for C and Vala projects; the latter especially as the GtkTemplate attribute can invoke GtkBuilder transparently.)