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. Resource path does not work...
Qt 6.11 is out! See what's new in the release blog

Resource path does not work...

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.2k 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
    dipanQt
    wrote on last edited by
    #1

    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
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by hskoglund
      #2

      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
      0
      • D Offline
        D Offline
        dipanQt
        wrote on last edited by
        #3

        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
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          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
          0
          • D Offline
            D Offline
            dipanQt
            wrote on last edited by
            #5

            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
            0

            • Login

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