Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 27
Registered: ‎01-03-2013
My Device: Curve 8520
My Carrier: Warid
Accepted Solution

accessing QML attached objects in C++ and best practice for handling UI in classes

Hi,

I have actually 2 queries

 

1) How we can access attachedobjects defined in QML in C++ ?

 

2) I am loving development on Blackberry 10 as C++ is one of my favorites. But I am a little lost when it comes to handling UI in classes. For example when we create project through momentics we have a class called ApplicationUI. It handles all the stuff of UI (by default) we do in C++ . like for example creating UI from qml document and setting as root etc. I am now working on an app that have NavigationPane as root and then I keep pushing pages (as screens) . But right now code for all pages is inside my ApplicationUI. What is the best practice for keeping UI logic of each page in a separte C++ class ?

I also develop for Android which has separate class for each Activity so code do not get mixed for each Activity. Please guide me how can I keep UI logic of each Page in separate C++ class ?

Developer
Posts: 27
Registered: ‎01-03-2013
My Device: Curve 8520
My Carrier: Warid

Re: accessing QML attached objects in C++ and best practice for handling UI in classes

For 1st question I have found that we have "attachedObjects" property to retrieve all attached objects.

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: accessing QML attached objects in C++ and best practice for handling UI in classes

regarding your second question:
i think it is the easiest approach to keep all UI things in QML. You can easily put things into separate files there.

if you want to use c++ for the UI: can be done, too. just put it in separate classes and include those in your application class.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 27
Registered: ‎01-03-2013
My Device: Curve 8520
My Carrier: Warid

Re: accessing QML attached objects in C++ and best practice for handling UI in classes

thanks.... for example if i have a qml file "test_screen.qml" .....is it a good practice that to handle its UI interaction in C++ I create a class "TestScreen" in test_screen.hpp/cpp file ?

 

secondly is it necessary to pass ApplicationUI object around to my other classes...or everything that I do in ApplicationUI can be done in other classes as well ?

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: accessing QML attached objects in C++ and best practice for handling UI in classes

These things depend on the complexity of your app.

I have different c++ classes that act as services or utils and they are all registered in qml, for example persistence, textutil, webservice etc

I handle all UI interactions in QML
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 27
Registered: ‎01-03-2013
My Device: Curve 8520
My Carrier: Warid

Re: accessing QML attached objects in C++ and best practice for handling UI in classes

Alright...thanks a lot... Smiley Happy