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. Mixing qrc and local QML files
Forum Updated to NodeBB v4.3 + New Features

Mixing qrc and local QML files

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

    Hi,

    I have 3 QML files:
    @
    // ComponentA.qml
    import QtQuick 2.0

    Item {
    ComponentB {}
    }
    @
    @
    // ComponentB.qml
    import QtQuick 2.0

    Item {
    ComponentC {}
    }
    @
    @
    // ComponentC.qml
    import QtQuick 2.0

    Item {}
    @

    ComponentA and ComponentC are in the qrc. ComponentB should be left in a local directory to be edited by a user.
    @
    <RCC>
    <qresource prefix="/">
    <file>ComponentA.qml</file>
    <file>ComponentC.qml</file>
    </qresource>
    </RCC>
    @

    Loading ComponentA logically causes an error because the QML engine can't find ComponentB in the ressource system.
    @engine.load(QUrl(QStringLiteral("qrc:/ComponentA.qml")));@
    @qrc:/ComponentA.qml:5 ComponentB is not a type@

    Is there any way to make the QML engine look for files in a specific local directory if they are not found in the ressource system?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi and Welcome to Qt Devnet,

      Since the first file that you are loading is in Resource System, further files will also be searched in Resource. The best way would be to use a "Loader":http://doc.qt.io/qt-5/qml-qtquick-loader.html Item to load the external file. For eg:
      @
      import QtQuick 2.4
      Item {
      Loader {
      source: "file:///home/as/ComponentB.qml"
      }
      }
      @

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SpongeBernd
        wrote on last edited by
        #3

        Works for ComponentB. But now ComponentC needs to be loaded by a Loader to get back to the resource system.

        @
        import QtQuick 2.4
        Item {
        Loader {
        source: "qrc:///ComponentC.qml"
        }
        }
        @

        Is there any more convenient way to let the engine handle the switching between ressources and local files automatically?

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          bq. But now ComponentC needs to be loaded by a Loader to get back to the resource system.

          The above code should work.

          bq. Is there any more convenient way to let the engine handle the switching between ressources and local files automatically ?

          I haven't come across any other way. May be "setBaseUrl()":http://doc.qt.io/qt-5/qqmlengine.html#setBaseUrl, but not sure though.

          157

          1 Reply Last reply
          0
          • F Offline
            F Offline
            feldifux
            wrote on last edited by
            #5

            Hi,
            I've just posted on a similar thread, how it is possible to mix qrc and non-qrc files with "V-Play":http://v-play.net...
            You can find the forum thread "here":http://qt-project.org/forums/viewthread/52478/P15/#217901.

            Cheers, Chris

            Founder of Felgo SDK - http://felgo.com/qt

            Felgo simplifies

            • Mobile App Dev with Qt esp. iOS & Android
            • Game Development with Qt

            What others say

            Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

            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