Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qml resuable component best practice
VinayBalajiRajputh last edited by
I am writing an application and for this I need 3 pages at the beginning depending upon user selections and also some minor logic changes. How do i encapsulate the elements? Should i create a single component i.e. mycom.qml and then in 3 pages create 3 objects and rewrite logic in handling on text changed? Or should i encapsulate just elements?
I have attached image for better understanding
It is better to create one re-usable component & 3 objects & adjust the logic to create the UI.
VInay123 last edited by
So you mean, in one qml file one whole page as shown in image and create 3 more objects out of this component?
But then i would have to implement logic for text edits in all 3 objects therefore in main component i have to expose all elements via property alias.. is this a good workflow?
Yes. It is right work-flow.
fcarney last edited by
implement logic for text edits in all 3 objects
You can put redundant/common logic in a separate js file that is imported in each qml file that it is needed. That should help reduce the logic footprint.