Results 1 to 3 of 3

Thread: QResource registering two resources with same file names inside

  1. #1
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question QResource registering two resources with same file names inside

    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...
    Last edited by frankiefrank; 26th April 2011 at 17:37.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QResource registering two resources with same file names inside

    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:
    Qt Code:
    1. QResource::registerResource ( "global.rcc", "/global" );
    2. QResource::registerResource ( "user.rcc", "/user" );
    3. QDir::setSearchPaths("icons", QStringList() << ":/user" << ":/global");
    To copy to clipboard, switch view to plain text mode 
    Then "icons:someicon.png" should look first in :/user then in :/global for someicon.png.

  3. The following user says thank you to ChrisW67 for this useful post:

    frankiefrank (27th April 2011)

  4. #3
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QResource registering two resources with same file names inside

    Thank you this is exactly what I wanted.


    Added after 54 minutes:


    Quote Originally Posted by ChrisW67 View Post
    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...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
    Qt Code:
    1. QResource::registerResource ( "global.rcc", "/global" );
    2. QResource::registerResource ( "user.rcc", "/user" );
    3. QDir::setSearchPaths("resourcedata", QStringList() << ":/user" << ":/global");
    To copy to clipboard, switch view to plain text mode 

    Now to get to the (potentially overloaded) logo, do I write "resourcedata/icons:logo.png" ?
    Last edited by frankiefrank; 27th April 2011 at 11:44.

Similar Threads

  1. Accessing version resources from inside the app
    By bnilsson in forum Qt Programming
    Replies: 5
    Last Post: 27th February 2010, 18:54
  2. QtHelp Module - registering compressed help file gives error
    By Ankitha Varsha in forum Qt Programming
    Replies: 1
    Last Post: 16th May 2008, 14:14
  3. qresource file alias problem with svg
    By giotto in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2008, 15:59
  4. moc with same file names?
    By cjhuitt in forum Qt Programming
    Replies: 9
    Last Post: 27th April 2007, 20:36
  5. Reading a unicode names from a file???
    By darpan in forum Qt Programming
    Replies: 7
    Last Post: 3rd May 2006, 17:28

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.