Adding Resources - Trainraider/gtk3-glade-c-template GitHub Wiki
Let's say you really need to add image.png to your project, but you don't want to scour the internet to learn how gresource works. It's easy.
- Place image.png into source/data
- Open data.gresource.xml.pre
It should look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="__PREFIX__">
<file>window_main.glade</file>
</gresource>
</gresources>
- Add a new line
<file>image.png</file>
like so:
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="__PREFIX__">
<file>window_main.glade</file>
<file>image.png</file>
</gresource>
</gresources>
There are other options such as compressing data like this:
<file compressed="true">image.png</file>
More info here.
And that's it. The build system will take care of the rest.
The resource can be referenced by GTK/Glib functions in your source code with its path: APP_PREFIX"/image.png"
. It might not look like it but that whole thing is a single string literal because APP_PREFIX is a macro which was defined in config.mk.
It can also be referenced within Glade, using the resource field of a widget, but you'll have to provide the full path, e.g. /com/email/name/template_app/image.png
.