Important: Please read the Qt Code of Conduct -

QFile::exists and Resource files

  • Hi all,

    I have the following .qrc file:

    <qresource prefix="/MYRES">



    In the 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/");@

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

    @QFile a(":/MYRES/");

    // Do something with the file

    // Do something with the file

    Contrary to what would be expected, a.exists returns false, but 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?

  • Lifetime Qt Champion


    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

Log in to reply