Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. File in QtResource file not found
Forum Update on Monday, May 27th 2025

File in QtResource file not found

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 919 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steve42
    wrote on last edited by
    #1

    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:

    <RCC>
        <qresource prefix="/">
            <file>OMSClient____ActionDefinitions.xml</file>
            <file>OMSClient____ADGroupDefinitions.xml</file>
            <file>OMSClient____AdminConfiguration.xml</file>
            <file>OMSClient____AlertSetup.xml</file>
            <file>OMSClient____ClientConfigTooltips.xml</file>
            <file>OMSClient____ClientConfiguration.xml</file>
            <file>OMSClient____DALDBEditorConfiguration.xml</file>
            <file>OMSClient____DALDBEditorStartup.xml</file>
            <file>OMSClient____DBEditorConfiguration.xml</file>
            <file>OMSClient____DefaultViewSetup.xml</file>
            <file>OMSClient____GlobalSetup.xml</file>
            <file>OMSClient____HtmlFiles.xml</file>
            <file>OMSClient____Icons.xml</file>
            <file>OMSClient____MaintenanceModule.xml</file>
            <file>OMSClient____MenuTree.xml</file>
            <file>OMSClient____Modules.xml</file>
            <file>OMSClient____PermissionDefinitions.xml</file>
            <file>OMSClient____Pixmaps.xml</file>
            <file>OMSClient____ReportConfigurationSyntax.xml</file>
            <file>OMSClient____SpareAircraftModule.xml</file>
            <file>OMSClient____SSIDBEditorStartup.xml</file>
            <file>OMSClient____SystemConfiguration.xml</file>
            <file>OMSClient_Guest_Guest__MenuTree.xml</file>
        </qresource>
    </RCC>
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      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
      OMSClient____ActionDefinitions.xml
      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 )

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Steve42
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3
          • S Offline
            S Offline
            Steve42
            wrote on last edited by
            #5

            Excellent! That fixed it. Thank you.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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 :-)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved