Problem with QFile and *.qrc



  • I have an app and two libraries linked to it. Each library has its own .qrc file with same prefix but different files. The only difference between libraries is one digit in name (name of everything - files, class, etc) and one function. Are the files in .qrc different or not - it doesn't matter, result is the same. And result is that when i'm trying to open inside an app QFile with the file from resource of the first library everything is OK. But when i'm trying to open file from the second library i got "Unknown error" from QFile.
    I've rebuilt the app and libraries but it didn't help.
    I know that QFile gives "Unknown error" at least when it can not find file in the resource file. But in my case this file is definitely there.
    What else can lead to this error or why QFile can't load file from the resource?



  • Another details emerged.
    When i change file in qrc to one with much more bigger size compiled library increasing its size too. So file is "compiled in". But QFile still gives "Unknown error" and QFile::exists( const QString& fileName ) returns false. Of course every path is correct.
    Why could such things happen?



  • Maybe you need to call "Q_INIT_RESOURCE":http://doc.qt.nokia.com/4.7/qdir.html#Q_INIT_RESOURCE in your application in order to initialize the second or subsequent resources.

    The name passed to the macro is that of your resource file (without the .qrc or .rcc extension).



  • Did it right before your post. Didn't help.
    But i have another details.
    There is static "const unsigned char qt_resource_name[]" array in avary qrc_*.cpp file. Array from the first library (whose resource file is loaded normally):
    @static const unsigned char qt_resource_name[] = {
    // forms
    0x0,0x5,
    0x0,0x6d,0x69,0x43,
    0x0,0x66,
    0x0,0x6f,0x0,0x72,0x0,0x6d,0x0,0x73,
    // ADV_6_2_v1_0.pdf
    0x0,0x10,
    0x2,0xb6,0xbc,0x86,
    0x0,0x41,
    0x0,0x44,0x0,0x56,0x0,0x5f,0x0,0x36,0x0,0x5f,0x0,0x32,0x0,0x5f,0x0,0x76,0x0,0x31,0x0,0x5f,0x0,0x30,0x0,0x2e,0x0,0x70,0x0,0x64,0x0,0x66,

    };@

    And array from the second one:
    @static const unsigned char qt_resource_name[] = {
    // forms
    0x0,0x5,
    0x0,0x6d,0x69,0x43,
    0x0,0x66,
    0x0,0x6f,0x0,0x72,0x0,0x6d,0x0,0x73,
    // ADV_6_3_v1_0.pdf
    0x0,0x10,
    0x2,0xb7,0x1c,0x86,
    0x0,0x41,
    0x0,0x44,0x0,0x56,0x0,0x5f,0x0,0x36,0x0,0x5f,0x0,0x33,0x0,0x5f,0x0,0x76,0x0,0x31,0x0,0x5f,0x0,0x30,0x0,0x2e,0x0,0x70,0x0,0x64,0x0,0x66,

    };@

    As i understand (and as says hexdump) the longest line of bytes is name of file. As expected this lines from both libraries are the same except one byte (0x33 in the second and 0x32 in the first).
    But why four byte legth lines (line #9 as says preview) are different (0x2,0xb7,0x1c,0x86 in the second)? What do these sequences of bytes mean?



  • As i can see from rcc's sources it's just a hash of the name of file, so nothing important.
    Just tried to copy the file from the first library and to change relevant record in .qrc file. Didn't help, QFile::exists(QString) still returns false.



  • Sorry, I don't have deeper knowledge of the format of the created binary resources.



  • [quote author="p-himik" date="1315554139"]As i can see from rcc's sources it's just a hash of the name of file, so nothing important.
    Just tried to copy the file from the first library and to change relevant record in .qrc file. Didn't help, QFile::exists(QString) still returns false.[/quote]

    You could iterate with QDir(":/") over the contents of the resources to look what's in it. It seems that some of the resources are just not loaded...



  • I am completely confused.
    After huge messing with source files it's finally working. I can not understand what happened because i've already tried complete rebuilding of this libraries (even with manual deletion of all generated files) and with no luck. But now sources are exactly the same as before and everything is working.
    In the next time first thing i'll do is just copying of sources towards and backwards.



  • Err. My mistake - did not change digit in the test code. Still doesn't work.

    Yeah! Now it's working! My mistake was naming resource files of different libraries with the same names.
    But i didn't find any word in documentation that naming of resource files is important.



  • Hm. I get that indirectly from

    @
    Q_INIT_RESOURCE( name )
    @

    If you use the same name twice, I would not expect two different resources to be initialized ;-)

    But you're right, it should be stated explicitly. I've added doc notes to [[Doc:QDir]] (for the Q_INIT_RESOURCE macro) and [[Doc:resources]].


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.