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. Loader wont find source when using several qrc files and relative paths
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.3k 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.
  • S Offline
    S Offline
    stefan14808
    wrote on last edited by
    #1

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

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

        yes, but it seems it has no effect

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MaxL
          wrote on last edited by
          #4

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

            thanks this seems to work

            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