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. Load QML files from file system when using new CMake qt_add_qml_module()
Forum Updated to NodeBB v4.3 + New Features

Load QML files from file system when using new CMake qt_add_qml_module()

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 3 Posters 1.5k Views 2 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.
  • K Offline
    K Offline
    Kai Nickel
    wrote on last edited by
    #1

    When using qt_add_qml_module(), all QML files are properly placed in a QRC which is in turn linked to the application. This is perfectly fine for deployment.

    However, during development I prefer loading my QML files directly from the file system. This eliminates the need for recompilation if only OML files are changed.

    There is a Qt 6.5 blog post regarding qt_add_qml_module which states the following:
    If we do want to load from the normal file system during development (to iterate faster on our QML files without having to recompile), we would be out of luck as we have now hard-coded the qrc path. With Qt 6.5 we have a new option which avoids all the issues.

    Source: https://www.qt.io/blog/whats-new-for-qml-modules-in-6.5

    Now my question is: HOW do we do this? WHAT is the new option in Qt 6.5 that enables us to do this?

    D 1 Reply Last reply
    1
    • K Kai Nickel

      When using qt_add_qml_module(), all QML files are properly placed in a QRC which is in turn linked to the application. This is perfectly fine for deployment.

      However, during development I prefer loading my QML files directly from the file system. This eliminates the need for recompilation if only OML files are changed.

      There is a Qt 6.5 blog post regarding qt_add_qml_module which states the following:
      If we do want to load from the normal file system during development (to iterate faster on our QML files without having to recompile), we would be out of luck as we have now hard-coded the qrc path. With Qt 6.5 we have a new option which avoids all the issues.

      Source: https://www.qt.io/blog/whats-new-for-qml-modules-in-6.5

      Now my question is: HOW do we do this? WHAT is the new option in Qt 6.5 that enables us to do this?

      D Offline
      D Offline
      d_h_mcinnes
      wrote on last edited by
      #2

      @Kai-Nickel , did you ever figure this out? I am facing the same issue

      K 1 Reply Last reply
      0
      • D d_h_mcinnes

        @Kai-Nickel , did you ever figure this out? I am facing the same issue

        K Offline
        K Offline
        Kai Nickel
        wrote on last edited by
        #3

        @d_h_mcinnes Sorry, I still have no clue

        Christian EhrlicherC 1 Reply Last reply
        0
        • K Kai Nickel

          @d_h_mcinnes Sorry, I still have no clue

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          See section "Loading Components: The state so far" which should describe what you are looking for.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          K 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            See section "Loading Components: The state so far" which should describe what you are looking for.

            K Offline
            K Offline
            Kai Nickel
            wrote on last edited by
            #5

            @Christian-Ehrlicher Thank you for pointing out this section.

            If I get you right, you propose to use the old variant with an explicit file path:

            engine.load("/path/to/Module/Main.qml");
            

            instead of the new method, which loads from qrc implicitly:

            engine.loadModule("Module", "Main");
            

            I think I get why this works for Main.qml (and maybe indirectly for all other Files in "Module", too?).

            But my application is comprised of multiple modules, each including qml files. How does the loading of "Main.qml" in the engine affect the way the qml files from my other modules are loaded?

            D 1 Reply Last reply
            0
            • K Kai Nickel

              @Christian-Ehrlicher Thank you for pointing out this section.

              If I get you right, you propose to use the old variant with an explicit file path:

              engine.load("/path/to/Module/Main.qml");
              

              instead of the new method, which loads from qrc implicitly:

              engine.loadModule("Module", "Main");
              

              I think I get why this works for Main.qml (and maybe indirectly for all other Files in "Module", too?).

              But my application is comprised of multiple modules, each including qml files. How does the loading of "Main.qml" in the engine affect the way the qml files from my other modules are loaded?

              D Offline
              D Offline
              d_h_mcinnes
              wrote on last edited by
              #6

              @Kai-Nickel , I found a way to do this, the details are in https://bugreports.qt.io/browse/QTBUG-120435

              K 1 Reply Last reply
              0
              • D d_h_mcinnes

                @Kai-Nickel , I found a way to do this, the details are in https://bugreports.qt.io/browse/QTBUG-120435

                K Offline
                K Offline
                Kai Nickel
                wrote on last edited by
                #7

                @d_h_mcinnes Thank you for the link, I finally got the time to try it myself.

                Setting the qml source directory as "prefer" in qmldir did the trick for me, too!

                To make this more feasible, I ended up setting NO_GENERATE_QMLDIR in qt_add_qml_module(), and providing my own patched qmldir in the RESOURCES list.

                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