Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Difference between qrc:/ and :/
Forum Updated to NodeBB v4.3 + New Features

Difference between qrc:/ and :/

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 4 Posters 3.2k Views 2 Watching
  • 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.
  • L Offline
    L Offline
    LScott
    wrote on last edited by
    #1

    My understanding from reading the documentation is that 'qrc:/...' and ':/...' are basically equivalent? Is this correct, or am I misunderstanding?

    If this is the case, why then does 'qrc:/...' work some places, and other places require ':/...' or it doesn't work?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      AFAIK, qrc:// is the protocol specifier like ftp:// or http://. :/ is a shortcut.

      Where did you saw the differences ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LScott
        wrote on last edited by
        #3

        @SGaist said in Difference between qrc:/ and :/:

        AFAIK, qrc:// is the protocol specifier like ftp:// or http://. :/ is a shortcut.

        So you mean :/ is a shortcut/alias for qrc:/?

        It seems the main place this occurs is loading components from QML files in the resource system into C++:

        QQmlApplicationEngine engine;
        engine.load(QUrl("qrc:/MyComponent.qml")); //Loads fine.
        engine.load(QUrl(":/MyComponent.qml"));      //File not found.
        

        But the opposite seems true using 'qmlRegisterType':

        qmlRegisterType("qrc:/MyComponent.qml", "my.uri", 1, 0, "MyComponent"); //'Warning: qmlRegisterType requires absolute URLs.
        qmlRegisterType(':/MyComponent.qml", "my.uri", 1, 0, "MyComponent"); //This works just fine.
        

        Investigating more, turns out using ":/MyComponent.qml", it seems to think it's a relative directory, so ends up resolving to "/home/lscott/qmlissue/build/debug/:/MyComponent.qml", when it should resolve to pretty much 'qrc:/MyComponent.qml".

        In this case the file 'MyComponent.qml" is located at the root of the 'qml.qrc' file, which is added to the '.pro' with

        RESOURCES += qml.qrc
        

        FYI, this is in Linux (Debian 8.7) with Qt v5.9.2 for G++.

        raven-worxR timdayT 2 Replies Last reply
        0
        • L LScott

          @SGaist said in Difference between qrc:/ and :/:

          AFAIK, qrc:// is the protocol specifier like ftp:// or http://. :/ is a shortcut.

          So you mean :/ is a shortcut/alias for qrc:/?

          It seems the main place this occurs is loading components from QML files in the resource system into C++:

          QQmlApplicationEngine engine;
          engine.load(QUrl("qrc:/MyComponent.qml")); //Loads fine.
          engine.load(QUrl(":/MyComponent.qml"));      //File not found.
          

          But the opposite seems true using 'qmlRegisterType':

          qmlRegisterType("qrc:/MyComponent.qml", "my.uri", 1, 0, "MyComponent"); //'Warning: qmlRegisterType requires absolute URLs.
          qmlRegisterType(':/MyComponent.qml", "my.uri", 1, 0, "MyComponent"); //This works just fine.
          

          Investigating more, turns out using ":/MyComponent.qml", it seems to think it's a relative directory, so ends up resolving to "/home/lscott/qmlissue/build/debug/:/MyComponent.qml", when it should resolve to pretty much 'qrc:/MyComponent.qml".

          In this case the file 'MyComponent.qml" is located at the root of the 'qml.qrc' file, which is added to the '.pro' with

          RESOURCES += qml.qrc
          

          FYI, this is in Linux (Debian 8.7) with Qt v5.9.2 for G++.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @LScott said in Difference between qrc:/ and :/:

          So you mean :/ is a shortcut/alias for qrc:/?

          yes both are the same. As @SGaist said qrc:/ is used where an url is expected and :/ where a file path is expected.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          3
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Can you provide a minimal compilable example that shows that behaviour ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • L LScott

              @SGaist said in Difference between qrc:/ and :/:

              AFAIK, qrc:// is the protocol specifier like ftp:// or http://. :/ is a shortcut.

              So you mean :/ is a shortcut/alias for qrc:/?

              It seems the main place this occurs is loading components from QML files in the resource system into C++:

              QQmlApplicationEngine engine;
              engine.load(QUrl("qrc:/MyComponent.qml")); //Loads fine.
              engine.load(QUrl(":/MyComponent.qml"));      //File not found.
              

              But the opposite seems true using 'qmlRegisterType':

              qmlRegisterType("qrc:/MyComponent.qml", "my.uri", 1, 0, "MyComponent"); //'Warning: qmlRegisterType requires absolute URLs.
              qmlRegisterType(':/MyComponent.qml", "my.uri", 1, 0, "MyComponent"); //This works just fine.
              

              Investigating more, turns out using ":/MyComponent.qml", it seems to think it's a relative directory, so ends up resolving to "/home/lscott/qmlissue/build/debug/:/MyComponent.qml", when it should resolve to pretty much 'qrc:/MyComponent.qml".

              In this case the file 'MyComponent.qml" is located at the root of the 'qml.qrc' file, which is added to the '.pro' with

              RESOURCES += qml.qrc
              

              FYI, this is in Linux (Debian 8.7) with Qt v5.9.2 for G++.

              timdayT Offline
              timdayT Offline
              timday
              wrote on last edited by
              #6

              @LScott I'd be curious to know if it works any better if you use qrc:/// ? That form is certainly used in the Qt docs http://doc.qt.io/qt-5/resources.html which has an example

              For example, the file path :/images/cut.png or the URL qrc:///images/cut.png would give access to the cut.png file"

              BTW I think something was changed with resource URIs in 5.9.1 because I ran into an issue with some previously OK usage of qrc:// (note just two slashes) described here.

              1 Reply Last reply
              2

              • Login

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