Accessing to QML data model object from C++ directly
-
wrote on 23 Sept 2015, 13:02 last edited by Kofr
Hi guys.
In my app I have C++ model and QML view.
Model is registered in C++ withqmlRegisterType<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?
example:.... qmlRegisterType<DataModel>("cpp.DataModel", 1, 0, "DataModel"); DataModel *dataModelObject = <<<code to get object registered as QML type>>> //how to embody this? ....
-
wrote on 23 Sept 2015, 13:18 last edited by
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.
1/2