Loader wont find source when using several qrc files and relative paths



  • Hi,

    i have an application with several qrc files.
    main.cpp:
    @
    view.engine()->addImportPath( ":/" );
    view.setSource(QUrl("qrc:/firstres/qml/main.qml"));
    @
    in main.qml is use components from another qrc file e.g. ComponentInSecondRes1, residing under qrc:/secondres/ComponentInSecondRes1.qml.
    When this components use the Loader component and specifiy its source likes this
    ComponentInSecondRes1:
    @ Loader{
    source: "ComponentInSecondRes2.qml"

        Component.onCompleted:  {
            console.log(source.toString())
        }
    }
    

    @

    I get this output:

    Starting app.exe...
    file:///execdir/:/secondres/ComponentInSecondRes2.qml.: File not found
    file::/secondres/ComponentInSecondRes2.qml

    A Loader in main.qml with source :/secondres/ComponentInSecondRes2.qml does work.
    Also everything works fine when using full qrc:/... URLs. I dont want to do this, so i can use the some code for using qrc and not.
    I tried initializing the other resources but this didnt help.
    Did i miss something?

    Regards Stefan



  • Have you try with Qt.resolvedUrl( url url ) ?
    http://qt-project.org/doc/qt-4.8/qml-qt.html#resolvedUrl-method



  • yes, but it seems it has no effect



  • Then how about creating a Component within the qml that will load it and then in your Loader use sourceComponent ? or simply try like you were doing but with sourceComponent instead of source



  • thanks this seems to work


Log in to reply
 

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