Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Resource path does not work...

    General and Desktop
    2
    5
    1185
    Loading More Posts
    • 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
      dipanQt last edited by

      I am fairly new to Qt, and I am trying to include a file using the Qt resource system.

      @RESOURCES += test.qrc@

      the test.qrc file reads
      @
      <RCC>
      <qresource prefix="/">
      <file>/somepath/somefile</file>
      </qresource>
      </RCC>
      @

      now, I am trying to access the file by the usual syntax,

      @QFile file("://somepath/somefile");
      ...
      @

      unfortunately, this just treats the ://somepath/somefile as a literal string somehow, and does not resolve the resource path!! I am clueless why that might be happening. Can anyone suggest why?

      1 Reply Last reply Reply Quote 0
      • hskoglund
        hskoglund last edited by hskoglund

        Hi, try change your test.qrc to:

        <RCC>
        <qresource>
        <file>somepath/somefile</file>
        </qresource>
        </RCC>
        

        and access it with:
        QFile file(":/somepath/somefile");

        P.S. Also, check that you can see your resource file in QtCreator in the Projects/Resources folder (verifying that the file path is correct.)

        1 Reply Last reply Reply Quote 0
        • D
          dipanQt last edited by

          Thanks for your reply.

          I have already tried those things, but none are working. I tried your modification also, but I got the same result. Am I missing something fundamental here?

          1 Reply Last reply Reply Quote 0
          • hskoglund
            hskoglund last edited by

            Hi, I tried with your test.qrc above (I created a new simple widgets app):
            first I checked that test.qrc showed up in the Qt Creator's Resources folder (underneath the Forms folder) also that I can doubleclick on somepath/somefile and that the contents appear in Qt Creator's edit window.
            Then i tested with my simple untitled widgets app, inserted 2 new include lines at the top:

            #include "QFile.h"
            #include "qDebug.h"
            

            added these 3 lines to get the contents of somepath/somfile:

            QFile file(":/somepath/somefile");
            file.open(QIODevice::ReadOnly);
            qDebug() << file.readAll();
            

            and sure enough the debug output shows the contents as well.
            Should work for you as well, I hope!

            1 Reply Last reply Reply Quote 0
            • D
              dipanQt last edited by

              Thanks hskoglund,

              I have found the issue. I was trying to run a script that I was loading as a resource. As I know now, that is not possible. Instead, I have to package the file, and I found a way to do that. Thanks to you of course, I was able to sort this out. When I saw that I can read the file but cannot access the path, then I realised, this is not what I wanted.
              Thanks again.

              • Dipan
              1 Reply Last reply Reply Quote 0
              • First post
                Last post