tiistai 24. syyskuuta 2013

Multilayered architecture in hybrid applications

I suggest that everyone who is interested in C++/QML hybrid programming reads this blog post from David Johnson (ICS). The text illustrates how a multilayered architecture can be used to easily integrate the visual QML elements into C++ logic with the use of QObject adaptation layer.

I have used this kind of architecture in my own hybrid programs, and the main advantages are:

  • Separation between logic and UI (between C++/Qt and QML)
    • The application UI/UX (visual elements, animations, behaviors, multimedia, shaders, etc.) can be entirely created in QML and it is practically isolated from the C++/Qt logic. This enables the parallel and isolated creation of UI/UX and logic by e.g. different development teams.
  • Easy communication between QML and C++/Qt
    • The QObject adapter can handle communication between the logic and QML. This can be done via signals and slots (works both ways), or by accessing the functions provided by QQuickItems (works only when information flows from logic to QML).
  • Efficient data containers for accessing QQuickItems
    • The QQuickItems (i.e. QML Items) are stored in a tree hierarchy that can be difficult to manage in C++/Qt logic. The QObject adapters on the other hand can be stored in any arbitrary data container (hashes, maps, lists...) thus enabling efficient access to the QQuickItems from logic.