Important: Please read the Qt Code of Conduct -

Open resource file

  • I have a file in my resource, I was wondering if is possible to run invisibly (not show the form).

  • I don't understand your question.

    If with "resource file" you mean a file that you have compiled into your binary using the "Qt Resource System":, it can be opened in a similar fashion to a local file by using QFile(":/"). Alternatively, the data of the resource file can be accessed directly via memory pointer by using QResource(":/").data(). With both ways the file won't be "visible" unless you make it visible.

  • Yes, is Qt Resource System, but i don't want to read, i want to run.

  • Run WHAT ???

    If the file is an executable you cannot run it from the memory directly! Instead you will have to save it to a local file (e.g. in TEMP folder), then use QProcess to run the executable from the local path...

    @QString localPath = QString("%1/program.exe").arg(QDir::tempPath());

    QFile localFile(localPath);

    QResource resourceFile(":\program.exe");
    if(localFile.write(, resourceFile.size()) != resourceFile.size())


  • @MuldeR
    Not work!
    Error message: no match method.
    I find is const uchar *, but write must use const uchar *....

            QFile file(myPath+"");
            //        QDataStream writer(file);
            QResource resourceFile(":/xxx/Resources/xxx/");
            file.write(, resourceFile.size());

    I am using Qt 5.4.

  • No nee to use the resource class, resource files can be accessed by QFile

    QFile resourceFile(":/path/to/resource");

  • This post is deleted!

  • @raf924
    I got this file with 0 byte.

    How to fixed it?

           QFile file(myPath+"/");
            //QDataStream writer(file);
            QFile resourceFile(":/xxx/Resources/xxx/");
            // QResource resourceFile(":/xxx/Resources/xxx/");

    In fact, I just want to set the default file for the beinning user.
    When user install this app, then he can get those free file.

    But I don't know how to set those code and files....

  • @mkdh You forgot to open the resource file.

Log in to reply