I need to write a BB-10 app. The app might have quite involved UI, with dynamic pages etc. I am thinking to write the application logic (data models, etc.) in C++. Should I use QML for UI design? How well and flexible is integration between C++ and QML? Will I not encounter some problems? My UI may consist of many QML pages (or dialogs, shown in Navigation Panes etc.), and when user clicks some actions in QML I may want to invoke some C++ code or navigate to other QML pages etc. Thank you for help.
3 Answers
I do not know anything about mobile development, but QML is nice, should make interfaces easier to maintain, modify and port to other devices.
Integration of QML and C++ is easy as long as you use well the Qt framework, using QObjects, Q_PROPERTY
and Q_INVOKABLE
methods... It is really easy.
EDIT: I must add, though, that I did not find accessing QML objects from C++ as easy as the contrary. This is because QML organizes objects in a hierarchy of few data types, and you have to discover child nodes dynamically, using findChild
or checking objectName
.
Anyway, since QML allows to bind properties, you should be able to create some C++ classes with your data, and access them on the UI without much effort ;)

- 11,745
- 6
- 59
- 86
-
In my app, I want to have following architecture. Probably have one NavigationPane object declared in C++. Then based on user's behaviour I may want to add pages to this NavigationPane object - I was thinking to have C++ class which would take care of adding these pages, and it would have methods like: openSettingsPage, openUsersDialog, etc. In QML I am thinking to implement UI part of these pages, but I also want to have corresponding C++ classes e.g., openSettingsPage.cpp, which would take care of data models. But then I need these objects to interact also. Do you think this is doable? how? – user2054339 Mar 09 '13 at 12:11
-
ps. I agree with you about findChild method, and thanks for recommendations about "binding properties" I will look into it further. – user2054339 Mar 09 '13 at 12:23
-
Yes, it's doable: in C++ you make a QObject with your data, make properties visible with Q_PROPERTY and bind them to your QML Component. You've many options here... You can create QML Components for the panel and the pages, with the ability to spawn pages from the QML itself, and then call QML functions from C++, or to have the panel and pages on QML and do all the spawn and hierarchy work via C++. – AkiRoss Mar 09 '13 at 14:32
i also go through such situation when you need control over application using C++ that qml not much do.best way inherit your class by NavigationPane and put there logic add your first page using QmlDocument::create()
if you had some page beside navigation use sheet and add some method to this class which Q_INVOKABLE
and pass setContext this class when ever you create new page using QmlDocument::create()
to access those methods .. finally never forget to add or handle OnTrasitionEnded(Page*)
signal to delete pages and release memory

- 1,849
- 3
- 14
- 18
Short answer: C++/QML integration is very good. May be very verbose at times, but there is nothing you can’t do in C++.
Even if doing everything in C++ is a tenny bit faster. BlackBerry is pushing the idea to code all the UI workflow in QML/Javascript.
The advantage would be clear separation between business logic & app flow. Another advantage is that QML is shorter to write and hopefully to maintain. Don’t forget that you can create new QML objects in C++.
onTriggered: {
var item = dataModel.data(indexPath);
if (item.count > 0) {
appLogic.updateFeed(item.id);
navPane.push(resultPage);
}
}

- 329
- 1
- 7