using loader or dynamically create component
-
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.
-
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.
@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_Vx5Ealso 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.htmlI would go with a Loader and set it to async mode to avoid blocking
-
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.
-
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.
@jpnurmi cool. learned about file selectors from your reply. sounds good.
-
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.
-
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.
-
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.
@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?