Accessing to QML data model object from C++ directly
In my app I have C++ model and QML view.
Model is registered in C++ with
qmlRegisterType<DataModel>("cpp.DataModel", 1, 0, "DataModel");
It is Ok to use it from QML, but how can I use this class's object from C++ again?
.... qmlRegisterType<DataModel>("cpp.DataModel", 1, 0, "DataModel"); DataModel *dataModelObject = <<<code to get object registered as QML type>>> //how to embody this? ....
With the code above you only register the Datatype!
You create the instance(s) in the qml-Part.
if you are using QQmlApplicationEngine you can search the rootObject for your instance you created in qml, or ( i think the simpler way ) create a instance and reqister it as ContextProperty.