Important: Please read the Qt Code of Conduct -

How to extract a resource from qrc (Solved)

  • Hi,

    I need extract 1 file on first run of my desktop application. My resource is in a qrc.

    How do it?


  • QFile::copy(":/path/to/qrc", "path/to/copy");
    copies the file from qrc to directory you specify. You can use other methods of QFile to load the file in memory.

  • Resources are completely transparent to the application and they might be treated as regular files, for example for copying (see previous post). The only restriction is that they are read-only, both the files itself (you cannot modify them) and the directory strucuture they are contained in (you cannot add or remove files to or from a resource collection).

  • Qt is wonderful -

    My simple question have a simple answer.


  • @pkj__
    I did as you said but I cannot write a QT resource file to a directory-structure-path.
    Here is my code:

    #include <QCoreApplication>
    #include <QFile>
    #include <QString>
    #include <QDebug>
    #include <QTextStream>
    #include <iostream>
    using namespace std;
    void read(QString filename)
        QFile file(filename);
        if(! |
            qDebug() << " Could not open the file for reading";
        QTextStream in(&file);
        QString myText = in.readAll();
        // put QString into qDebug stream
        qDebug() << myText;
    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        bool status = QFile::copy(":/resources/" , "~/abc/");
        if(status) {
                cout << "Success" << endl;
            } else {
                cout << "Failed" << endl;
        return 0;

    Could you help me why I am getting Failed. I am expecting that I will create a new folder named abc inside the current directory and copy the resource file into that.
    Thank and best regards.

    Thanh C. Tran

  • Lifetime Qt Champion

    Copy will not make a new folder
    You must do that yourself


  • @mrjj
    Thanks, problem solved.
    Best regards,
    Thanh C. Tran

Log in to reply