Difference between qrc:/ and :/



  • 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?


  • Lifetime Qt Champion

    Hi,

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

    Where did you saw the differences ?



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


  • Moderators

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


  • Lifetime Qt Champion

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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.