Qml resuable component best practice
-
Hello everyone,
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.
-
@dheerendra
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.
-
@VInay123 said in Qml resuable component best practice:
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.