PDA

View Full Version : QResource registering two resources with same file names inside



frankiefrank
26th April 2011, 17:13
I'm working with pre-generated "rcc" resource files I'm loading during run-time.

I want to have a hierarchical resource mechanism - one "rcc" file has resources on the application level. After that a user specific resource file is registered.

If both of my resource files have the file "logo.png", after registering both rcc files with QResource::registerResource how can I differentiate the two different files?

I understand I could use the alias mechanism (or alternatively the prefix) to make sure every access is fully qualified ":global/logo" as opposed to ":user/logo") BUT then I'd have to wrap every access so that the user accesses the correct file.

Ideally I'd have some way of saying ":logo.png" and getting the correct file based on the user's resource override.

Any tips on the matter?

Also - is the default behavior overriding the files? I coded it and think it is but just to be sure...

ChrisW67
26th April 2011, 23:22
Use the second argument of the QResource::registerResource() to "mount" the user resources at a known point in the virtual resource tree. Then use the QDir::setSearchPaths() method to set the search path for file types. Something like:


QResource::registerResource ( "global.rcc", "/global" );
QResource::registerResource ( "user.rcc", "/user" );
QDir::setSearchPaths("icons", QStringList() << ":/user" << ":/global");

Then "icons:someicon.png" should look first in :/user then in :/global for someicon.png.

frankiefrank
27th April 2011, 07:43
Thank you this is exactly what I wanted.

Added after 54 minutes:



Then "icons:someicon.png" should look first in :/user then in :/global for someicon.png.

I'm guessing you meant ":icons/someicon.png"

Ah no, now I see how it works:
http://doc.trolltech.com/latest/qdir.html#setSearchPaths

But how would if my resource file has some sub folder that are also mutual, how would that work?

For example, if both the global and the user resource files contain:
readme.txt
icons/logo.png


QResource::registerResource ( "global.rcc", "/global" );
QResource::registerResource ( "user.rcc", "/user" );
QDir::setSearchPaths("resourcedata", QStringList() << ":/user" << ":/global");


Now to get to the (potentially overloaded) logo, do I write "resourcedata/icons:logo.png" ?