Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to read file from QRC?



  • Hey

    Bit annoying but I have this in QRC:

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

    And I wish to load it as :

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

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

    What to do ?

    TIA


  • Lifetime Qt Champion

    Hi
    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 ":" !

    "/openGL/testX"
    to
    ":/openGL/testX"

    Blindness...


  • Lifetime Qt Champion

    @Dariusz
    Hi
    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