You can register a global QML object in you main.cpp
which poins to an arbitrary QObject.
Brain *brain = new Brain();
QQmlApplicationEngine engine;
QQmlContext *context = engine.rootContext();
context->setContextProperty("brain", brain);
Now you have brain
available globally in QML. You can pass it to a custom component, for example
VisibleComponent {
id: vico1
width: 300
height: 300
Component.onCompleted: {
vico1.setLogic(brain)
}
}
This requires a Q_INVOKABLE void setLogic(Brain* brain);
in VisibleComponent
.
I have a running example project of this code, let me know if you need it.