Important: Please read the Qt Code of Conduct -

[solved]Unable to open resource file

  • Hi,

    I added a resource file "myresourcestuff.qrc" to my project "StringFinder"
    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = StringFinder
    TEMPLATE = app

    SOURCES += main.cpp

    HEADERS += stringfinder.h

    FORMS += stringfinder.ui

    RESOURCES += myresourcestuff.qrc

    and the "myresourcestuff.qrc" looks like this:
    <qresource prefix="/new/prefix1">

    "stuff.txt" is located on the same path as the .ccp, .h, .qrc - files.

    Now I'm trying to access that file in "stringfinder.cpp"

    // works
    //QFile myFile("C:/research/Qt/Qt5.2.0/Tools/QtCreator/bin/StringFinder/stuff.txt");
    // doesn't work
    QFile myFile(":/new/prefix1/stuff.txt");

        ui->textEdit->setText("opening file");;
        QTextStream textStream(&myFile);
        QString line = textStream.readAll();
        QTextCursor textCursor = ui->textEdit->textCursor();
        textCursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
        ui->textEdit->setText("File not found");


    but it won't open, myFile.exists() returns "false" :/

    Can anyone help please? A minimal project is uploaded here:


  • Hi BenBenJones. Welcome to devnet.
    The minimal project works ok. It is very strange that you get errors. Try "clean", "qmake", "rebuild all".

  • Qt Champions 2017

    This should work without any problem. Just check the file extn. Some times it will somestuff.txt.tx. It may not be visible in the windows explorer. This is the only issue I suspect now.

  • Thanks, “clean”, “qmake”, “rebuild all” was the solution!!

Log in to reply