TransWikia.com

gtkmm load from resource plain text file

Stack Overflow Asked by Tophyd Ayur on December 19, 2020

I have a simple resource xml file looks like

<?xml version="1.0" encoding="UTF-8" ?>
<gresources>
    <gresource prefix="ui"> 
        <file preprocess="xml-stripblanks">ui.glade</file>
    </gresource>
    <gresource prefix="text-data">
        <file>definitions.txt</file>
    </gresource>
</gresources> 

And UI loaded without problem

refBuilder->add_from_resource("/ui/ui.glade");

But I do not know how to load and read the text file that is defined in the resource file as "definition.txt".

One Answer

You are able to retrieve the file contents with one of two static methods of Gio::Resource class: open_stream_global or lookup_data_global. Here are their signatures:

  • Glib::RefPtr< InputStream > open_stream_global (const std::string& path, ResourceLookupFlags lookup_flags=RESOURCE_LOOKUP_FLAGS_NONE)
  • Glib::RefPtr< const Glib::Bytes > lookup_data_global (const std::string& path, ResourceLookupFlags lookup_flags=RESOURCE_LOOKUP_FLAGS_NONE)

As you can see, the difference between them is how you access data: via a Gio stream class or Glib::Bytes (a "data array": byte contents + length).

Answered by RodolfoRG on December 19, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP