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. using loader or dynamically create component
Forum Updated to NodeBB v4.3 + New Features

using loader or dynamically create component

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 3.1k 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.
  • L Offline
    L Offline
    literA2
    wrote on last edited by
    #1

    I would like to seek your opinion in this case:

    I have an app with different layouts in every platform, so I created different Forms.

    Which is more viable to use, loader or create component dynamically depending on platform. Does loader work efficiently and not use too much memory?

    I am having problem passing properties when creating object using createObject function. In my Form component i used repeater to display components into column. I used VisualItemModel for form components, however i encountered few errors while doing it.

    //Form
    Item {
      property alias model: repeater.model
      Column {
        anchors.fill: parent
        spacing: 0
    
        Repeater {
          id: repeater
       }
     }
    
     // Page
     Item {
       // This is how I set the form in static
       Form {
         model: VisualItemModel {
           Checkbox {}
           Switch {}
           TextField {}
         }
       }
     }
    

    Can you please advise how to create the form using createObject function?

    I tried creating static VisualItemModel in each platform and pass it through in createObject however, the unused model encountered an error due to null parent.

    Please advise. Thanks.

    ekkescornerE 1 Reply Last reply
    0
    • L literA2

      I would like to seek your opinion in this case:

      I have an app with different layouts in every platform, so I created different Forms.

      Which is more viable to use, loader or create component dynamically depending on platform. Does loader work efficiently and not use too much memory?

      I am having problem passing properties when creating object using createObject function. In my Form component i used repeater to display components into column. I used VisualItemModel for form components, however i encountered few errors while doing it.

      //Form
      Item {
        property alias model: repeater.model
        Column {
          anchors.fill: parent
          spacing: 0
      
          Repeater {
            id: repeater
         }
       }
      
       // Page
       Item {
         // This is how I set the form in static
         Form {
           model: VisualItemModel {
             Checkbox {}
             Switch {}
             TextField {}
           }
         }
       }
      

      Can you please advise how to create the form using createObject function?

      I tried creating static VisualItemModel in each platform and pass it through in createObject however, the unused model encountered an error due to null parent.

      Please advise. Thanks.

      ekkescornerE Offline
      ekkescornerE Offline
      ekkescorner
      Qt Champions 2016
      wrote on last edited by ekkescorner
      #2

      @literA2 you should take a llok at a session from Qt Summit 2015 about Memory Management,
      where this is explained in detail:
      https://www.youtube.com/watch?v=77LH_I_Vx5E

      also about Effective QML:
      https://www.youtube.com/watch?v=vzs5VPTf4QQ
      (goto Tip #15)

      and about QML Mistakes:
      https://www.youtube.com/watch?v=sM0u9_l4grM
      (goto #4 about Loader vs createObject()

      also there's a documentation:
      https://doc-snapshots.qt.io/qt5-5.6/qtquick-performance.html

      I would go with a Loader and set it to async mode to avoid blocking

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.8 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

      1 Reply Last reply
      2
      • jpnurmiJ Offline
        jpnurmiJ Offline
        jpnurmi
        wrote on last edited by jpnurmi
        #3

        Qt offers a solution called "file selectors" for loading platform specific files in a manner that is entirely transparent to the app. QQmlApplicationEngine sets it up for you automatically, so all you need is to organize the platform-specific variants into +<platform> subfolders.

        • http://doc.qt.io/qt-5/qqmlfileselector.html
        • http://www.ics.com/blog/mastering-qt-file-selectors
        • http://www.embeddeduse.com/2015/09/12/responsive-qml-hmis-with-file-selectors/
        ekkescornerE 1 Reply Last reply
        1
        • jpnurmiJ jpnurmi

          Qt offers a solution called "file selectors" for loading platform specific files in a manner that is entirely transparent to the app. QQmlApplicationEngine sets it up for you automatically, so all you need is to organize the platform-specific variants into +<platform> subfolders.

          • http://doc.qt.io/qt-5/qqmlfileselector.html
          • http://www.ics.com/blog/mastering-qt-file-selectors
          • http://www.embeddeduse.com/2015/09/12/responsive-qml-hmis-with-file-selectors/
          ekkescornerE Offline
          ekkescornerE Offline
          ekkescorner
          Qt Champions 2016
          wrote on last edited by
          #4

          @jpnurmi cool. learned about file selectors from your reply. sounds good.

          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
          5.15 --> 6.8 https://t1p.de/ekkeChecklist
          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

          1 Reply Last reply
          0
          • L Offline
            L Offline
            literA2
            wrote on last edited by literA2
            #5

            Thank you @ekkescorner for your inputs, I'll take time to view and read them.

            @jpnurmi thank you! I'm actually aware of the fileselector however, we're not inclined to use it because we wanted to limit the qml pages for different layouts. However, using it into components is possible.

            1 Reply Last reply
            0
            • jpnurmiJ Offline
              jpnurmiJ Offline
              jpnurmi
              wrote on last edited by
              #6

              Notice that there's a major difference between file selectors and dynamic component creation. The former is in many cases superior from performance perspective. You won't spend extra CPU cycles for dynamically loading something that never changes, and more importantly, it encourages you to write simpler QML code.

              L 1 Reply Last reply
              0
              • jpnurmiJ jpnurmi

                Notice that there's a major difference between file selectors and dynamic component creation. The former is in many cases superior from performance perspective. You won't spend extra CPU cycles for dynamically loading something that never changes, and more importantly, it encourages you to write simpler QML code.

                L Offline
                L Offline
                literA2
                wrote on last edited by literA2
                #7

                @jpnurmi thanks for additonal infos.

                I noticed this when using QQmlFileSelector, i needed to create a blank Form qml file on parent directory of these folders: +android, +ios. And the imports on platform specific forms should follow as if it resided on its parent directory. Or i should decide which form to use as default. am i correct?

                1 Reply Last reply
                0
                • jpnurmiJ Offline
                  jpnurmiJ Offline
                  jpnurmi
                  wrote on last edited by
                  #8

                  Yes, with file selectors you always need a default/fallback file. Otherwise an alternate won't be looked up. Which of the two alternates serves a better default if/when your app is run outside the two platforms? :)

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved