Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

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

    QML and Qt Quick
    2
    5
    1993
    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.
    • S
      stefan14808 last edited by

      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

      1 Reply Last reply Reply Quote 0
      • M
        MaxL last edited by

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

        1 Reply Last reply Reply Quote 0
        • S
          stefan14808 last edited by

          yes, but it seems it has no effect

          1 Reply Last reply Reply Quote 0
          • M
            MaxL last edited by

            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

            1 Reply Last reply Reply Quote 0
            • S
              stefan14808 last edited by

              thanks this seems to work

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