Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt6 how to load qml sources at runtime
Forum Updated to NodeBB v4.3 + New Features

Qt6 how to load qml sources at runtime

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 579 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.
  • D Offline
    D Offline
    d_h_mcinnes
    wrote on last edited by
    #1

    Hi
    How do I make a qt6 cmake-based app load qml sources at runtime? I have an embedded target, and I want to be able to edit qml files on the device instead of recompiling & redeploying.

    I have example code here: https://github.com/DanielMcInnes/helloQmlTc branch: 'load-qml-at-runtime')

    I can't see any options in qt_add_qml_module that do what I want. NO_CACHEGEN doesn't do it.

    I tried the following, without success. Any edits after building are ignored.

    Loader {
    		anchors.bottom: parent.bottom
    		source: "file:///path/to/MyRectangle.qml"
    	}
    
    Axel SpoerlA 1 Reply Last reply
    0
    • D d_h_mcinnes

      Hi
      How do I make a qt6 cmake-based app load qml sources at runtime? I have an embedded target, and I want to be able to edit qml files on the device instead of recompiling & redeploying.

      I have example code here: https://github.com/DanielMcInnes/helloQmlTc branch: 'load-qml-at-runtime')

      I can't see any options in qt_add_qml_module that do what I want. NO_CACHEGEN doesn't do it.

      I tried the following, without success. Any edits after building are ignored.

      Loader {
      		anchors.bottom: parent.bottom
      		source: "file:///path/to/MyRectangle.qml"
      	}
      
      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      @d_h_mcinnes
      You're doing the right thing. The path to MyRectangle.qml must be available at run time. You might wanna at the qml file as a resource, to be sure of that.

      Software Engineer
      The Qt Company, Oslo

      D 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        @d_h_mcinnes
        You're doing the right thing. The path to MyRectangle.qml must be available at run time. You might wanna at the qml file as a resource, to be sure of that.

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

        @Axel-Spoerl Thank you. By adding the qml file as a resource, and doing:

        Loader {
            source: "file:///path/to/MyRectangle.qml" // loads qml at runtime
            // source: "qrc:/MyRectangle.qml"         // loads whatever the source was at compile time
        }
        

        ... I can get a Loader to load qml at runtime. However, for my use case, I need all of my qml types to load at runtime without using a Loader.

        eg. in the following code, I need 'first' to be loaded at runtime.

        	MyRectangle { id: first } // this is defined at compile time
        
        	Loader {
        		anchors.bottom: parent.bottom
        		source: "file:///path/to/MyRectangle.qml"  // this is defined at run time
        	}
        

        I think this might be a bug / lack of documentation, I'll file a bug and see what the developers say.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          d_h_mcinnes
          wrote on last edited by
          #4

          created https://bugreports.qt.io/browse/QTBUG-120435

          D 1 Reply Last reply
          0
          • D d_h_mcinnes

            created https://bugreports.qt.io/browse/QTBUG-120435

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

            @Axel-Spoerl , fyi I got a reply in my bug report that got this working for me. The details are in the ticket, but the magic step is to manually remove the 'prefer' line from MyModule/qmldir in the build directory.

            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