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. QFile::exists and Resource files
Qt 6.11 is out! See what's new in the release blog

QFile::exists and Resource files

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.3k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fsilva
    wrote on last edited by
    #1

    Hi all,

    I have the following .qrc file:

    @<RCC>
    <qresource prefix="/MYRES">

    <file>DLLs.zip</file>

    </qresource>
    </RCC>@

    In the DLLs.zip file I have several .dll files, lets say a.dll, b.dll, c.dll...

    Now I need to check if the expected .dll files are in fact in the zip file. So what I did was:

    @bool exists = QFile::exists(":/MYRES/DLLs.zip/a.dll");@

    Now I also need to do something with the file, so I changed the previous code to:

    @QFile a(":/MYRES/DLLs.zip/a.dll");

    if(a.exists())
    {
    // Do something with the file
    }

    if(a.open(QIODevice::ReadOnly))
    {
    // Do something with the file
    }
    @

    Contrary to what would be expected, a.exists returns false, but a.open returns true. It seems kind of weird that I can open a file that does not exist!

    Can someone tell me why this happens? Could it be a Qt bug?

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

      Hi,

      AFAIK, you have a pretty unusual use case here. Using a compressed file to be included in the resources that are themselves already compressed in the same format. I'd say that it might be pure luck that it's working like that.

      However to ensure that what you do is correct and if there's a bug somewhere, you should rather ask this on the interest mailing list. You'll find there Qt's developers/maintainers. This forum is more user oriented

      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
      0

      • Login

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