Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to read file from QRC?
QtWS25 Last Chance

How to read file from QRC?

Scheduled Pinned Locked Moved Solved General and Desktop
qrc
4 Posts 2 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dariusz
    wrote on 1 Jun 2019, 12:44 last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 1 Jun 2019, 12:53 last edited by mrjj 6 Jan 2019, 12:54
      #2

      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

      1 Reply Last reply
      4
      • D Offline
        D Offline
        Dariusz
        wrote on 1 Jun 2019, 13:03 last edited by
        #3

        Hey

        Thanks for info!

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

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

        Blindness...

        M 1 Reply Last reply 1 Jun 2019, 21:03
        1
        • D Dariusz
          1 Jun 2019, 13:03

          Hey

          Thanks for info!

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

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

          Blindness...

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 1 Jun 2019, 21:03 last edited by
          #4

          @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.

          1 Reply Last reply
          0

          2/4

          1 Jun 2019, 12:53

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved