When using QML & C++ what is the best practice of connecting the view/controller to the model?
-
I've gone throgh 3 diffirent itterations overtime each less bad than the last but still having issues.
Iteration 1
Having multiple diffirent classes for each subsystem with their models completley combined with their view/controller in code and all connections handled via qml.
This one has no seperation between model and view/controller code and handles a great deal of model code in the qml end, which is definitley far from ideal, and makes modifiying code hell.
Iteration 2
Registering all C++ subsystems as singletons, and handling their interactions and connections in a few diffirent connection management claasses.
This one was a much better approach as at least the model part of the code is no longer run in Qml, however Models and views/controllers are still in the same classes and we haven't achieved a full seperation.
Iteration 3
Defining the model/view classes (i.e. the classes that expose themselves to C++ in a completley seperate library from all other subsystems. These subsystem then register themselves with a GUI singleton Manager, that I will call
GuiSystem
here in the constructor via the use of a passkey idiom.Once registed with the
GuiSystem
the singleton will generate a signal that will then be used be connected to a subsystem via one of the earlier mentioned connection managing classes, this class will then setup connections between the SubSystems & the Gui objects.This approach will get rid of most singletons and fully seperate models and views from controllers, however it would create a single large singleton that I can see being almost unmanagable in the future, wheras ideally I would like to eventually get rid of all singletons from my project.
I'm still in the process of transferring fom Iteration 2 -> 3 atm so this hasn't been fully implemented, although I see it making the model code, and the
qml
code more managable, I imagine as the code grows, it would be less managable overtime.Final Part
So what would you consider to be the best practice of setting up communication between the qml C++ interface and the subystems, without having a large negative impact on performance or code design?