Qt World Summit: Register Today!

File in QtResource file not found

  • I have several XML files in a Qt Resource file. Everything works great on Linux. But on Windows, at runtime, it appears the Resource file does not have anything in it, at all. The qrc cpp file is built, and is sufficiently large enough so I am guessing all the files I want have been built into it.

    I originally created the Resource file using Qt Creator on Linux. Using Qt Creator on Windows I can open the XML files from the Resource file.

    I am using this line to access them:

    QDirIterator it( ":", QStringList() << "*.xml", QDir::Files );

    For testing purposes, I tried this:

    QDir qDir( ":" );
    QStringList listFiles = qDir.entryList();

    and looped through listFiles, but it just had some files that I read somewhere were the general things that were always there.

    I'm certainly not a Qt expert by any means, and this is my first attempt to use Qt Resource files. Why would this work on Linux but not Windows?

    Here is the QRC:

        <qresource prefix="/">

  • Lifetime Qt Champion

    Just tested on windows with

    QDirIterator it( ":", QStringList() << "*.jpg", QDir::Files );
      while(it.hasNext()) {
        qDebug() << it.next();

    and it does list my .jpg from resource.

    Then i tried adding a file name
    and it listed that too. ( when looking for *.xml)

    So really not sure why it wont work for you.

    Also, you can open resource file and click on one xml and it will so so clearly
    it ok with the names/location.

    Could you make a small test project showing this not working and zip project and
    paste link here to have a look on ?
    (you can upload .zip so need google / dropbox or alike )

  • Well this is really annoying. The little test project I was making for you works correctly. I structured it as closely as possible to where I am seeing the problem, which really means the qrc and the xml files are in a subdirectory from where the cpp file is that is trying to read the files. And it works in the test program. The only other difference I can think of is that where I have the problem, the resource file (with the XML files) and the cpp file that is attempting to read them are in a library that is linked in to the main executable. So, any ideas?

  • Lifetime Qt Champion


    That's a crucial point you didn't mention, see the Using Resources In A Library part int the resource chapter of Qt's documentation and the Q_INIT_RESOURCE macro.

  • Excellent! That fixed it. Thank you.

  • Lifetime Qt Champion

    You're welcome !

    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :-)

Log in to reply