Important: Please read the Qt Code of Conduct -

Ressource File Url not opened by QFile

  • Hello Everyone,

    I have attached herewith a simple project using a simple resource file that cannot be opened by QFile. I have just built the latest version of QT5.11 from source using Git and Qt Creator 4.7.82 from source (latest git version check out). For both, I used the same Visual Studio Enterprise 2017 version 15.7.2.

    Can anyone please tell me what could be wrong?

    Thanks in Advance.
    [0_1527563530808_TestQFile.rar](Uploading 100%)

  • I dont understand you cleary. You have a TestQFile.rar in your Resource and you just want to access it with the Url in a QFile? The Problem is maybe that everything in the Resource File, that is compiled into your Executable, is ReadOnly.

  • Lifetime Qt Champion


    What error do you get ?

    What code are you using ?

    By the way, upload of compressed archived are not enabled.

  • Hello and thanks for the answers.
    I have a simple .txt file and I try to access it with QFile::open(). The following if always fails, no matter which projects[0_1527616248419_textfinder.cpp](Uploading 100%) :

    QFile inputFile("qrc:/Resources/input.txt");
        if (!{
            qDebug() << "could not open " << inputFile.fileName() <<"\n";
            if (QFile::exists("qrc:/Resources/input.txt")){
                qDebug() << "could not find existing file " << inputFile.fileName() <<"\n";

    The console gives me:

    Starting E:\Qt\Tutorials\QtCreator\build-TextFinder-x64-Debug\debug\TextFinder...
    could not open  "qrc:/Resources/input.txt" 
    E:/Qt/Tutorials/QtCreator/build-TextFinder-x64-Debug/debug/TextFinder exited with code 0

    [0_1527616275931_textfinder.cpp](Uploading 100%)
    [0_1527616287093_textfinder.qrc](Uploading 100%)

  • Lifetime Qt Champion

    You should use :/ to access your resources like shown here.

    Can you post your .qrc file content ?

  • Sorry for my absence. I have tried almost every combination of /,//,///,\ and so on.
    My Qrc file content is

        <qresource prefix="/" lang="C++">

  • Lifetime Qt Champion

    And you are using the plugin and are sure the files are actually compiled into the code ?

    I would do something like

    QDirIterator it(":", QDirIterator::Subdirectories);
    while (it.hasNext()) {
        qDebug() <<;

    to see what you got.

    alt text
    alt text

Log in to reply