Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

A tree like Qt object architecture and QML



  • Hello there,
    In the project I am developing the requirements changed and it came out that my current way of connecting the Qt backend with QML frontend is not fit anymore. I had 2 classes that could talk to QML through context property. One of the class was one of its kind in the whole program, the other one was packed into a list.

    But now, the backend part looks like a tree... There has to be the main object, that has n second level objects inside, where each second level object has n third level objects inside etc... Now I need to figure out what is the best way of connecting the Qt part with QML together. When thinking about creating a property setter/ getter for each possible property (variable) my head starts to hurt. This has to be more universal and easy to extend, no matter how many branches/ levels/ properties are needed.

    0_1556006875920_e0294328-8173-48d8-8cbf-a6764d23804f-obraz.png

    I thought of creating a dedicated communication protocol, ie. a single pair of signal/ slot with dedicated data frame but this also seems hard to maintain in the longer run.

    I would appreciate all hints regarding this issue.


  • Lifetime Qt Champion

    Hi,

    Wouldn't the MVC pattern be of help here ? You create a model that represents your tree of objects and interact with it rather than trying to make all objects available directly.



  • @SGaist hi, thanks for answer. Actually I am trying to do this with MVC, but I cant figure out how to do this properly in qml because of the tree architecture + the fact that each branch can exist in more than one instances.


  • Lifetime Qt Champion

    It should be a tree of QObject and then you can use slots/Q_INVOKABLE methods/etc. to interact with them.


Log in to reply