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 hasn
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.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.
-
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.
-
It should be a tree of QObject and then you can use slots/Q_INVOKABLE methods/etc. to interact with them.