3

Before I start, I know of the existence of GResource, however I'm using gtkmm (C++), and I'm not sure if GResource works with C++. I can't find anything along the lines Glib::GResource, and I've been looking for a while.

Anyway, I'm writing a GUI using Gtkmm, and I want to pack the .glade file which I load within the executable, so that the executable can be run without having to have a file next to it. I'm not sure that I completely understand how GResources work, and I can't find any clear instructions anywhere.

So, using Gtkmm, how would I pack a .glade file inside my executable?

update: I've found this. (Gio::Resource), which sounds hopeful, but no documentation.

Jacob Garby
  • 773
  • 7
  • 22

1 Answers1

5

I've made some more research and found this tutorial and this documentation. Looks like what you need is Gio::Resource::lookup_data_global. Below is C version of my answer.


When something in glib world lacks documentation, it's time to read documentation for c. In short: with the help of glib-compile-resources and a simple xml file you build a .c file, which can be compiled into your application. After that you can use g_resources_lookup_data (resourceS, it's important) to load data.

Alexander Dmitriev
  • 2,483
  • 1
  • 15
  • 20
  • Thanks! From the second link you posted: `Once a resource is registered the files in it can be accessed with the global resource lookup functions like g_resources_lookup_data().`. That's talking about the function `void Gio::Resource::register_global()`. Do I, then, need to call this function before being able to use my resource? – Jacob Garby Jun 18 '18 at 21:36
  • Quote: _There are two forms of the generated source, the default version uses the compiler support for constructor and destructor functions (where available) to automatically create and register the Gio::Resource on startup or library load time. If you pass –manual-register, two functions to register/unregister the resource is instead created._ – Alexander Dmitriev Jun 18 '18 at 21:39
  • Oh, I didn't see that. Seems like I won't have to call the register function myself then :) – Jacob Garby Jun 18 '18 at 21:42