Important: Please read the Qt Code of Conduct -

How to read file from QRC?

  • Hey

    Bit annoying but I have this in QRC:

        <qresource prefix="/">
        <qresource prefix="/openGL/">
            <file alias="testX">file/test.glsl</file>

    And I wish to load it as :

    QString path = "/openGL/testX"
    void loadShader(QString filePath){
        QFile v(filePath);;
        qDebug() << v.readAll();
        if (!mShader->addShaderFromSourceFile(QOpenGLShader::Vertex, v.readAll())) {

    This seems to not work...
    device not open bla bla bla...

    What to do ?


  • Lifetime Qt Champion

    When having files in a resource file, the syntax for its paths is
    ":/xxx" . note the start :
    Anyway, find the file in the project explorer tree and right click the file.
    You can then copy the complete path to use.

    alt text

  • Hey

    Thanks for info!

    I had another deep look at what I was doing... I forgot to add ":" !



  • Lifetime Qt Champion

    Thats why i often use the copy trick :)
    ctrl+k type some of the name, press enter, right click and copy
    Almost as fast as writing it when i have nested folders.

Log in to reply