Re: How to get Object's pointer instantiated in QML engine
I have
Code:
qmlRegisterType<DataModel>("one.DataModel", 1, 0, "DataModel");
and I instance this in QML
I need to get pointer to the istantiated objct in C++ side. BUT I do not want to use aproach with use of .
How to get a pointer?
I have
Code:
qmlRegisterType<DataModel>("one.DataModel", 1, 0, "DataModel");
and I instance this in QML
I need to get pointer to the istantiated objct in C++ side. BUT I do not want to use aproach with use of .
How to get a pointer?
Added after 30 minutes:
I got the solution
Code:
QObject *dataModel
= engine.
rootObjects()[0]->property
("refToMainModelForC").
value<QObject
*>
();
qDebug() << dataModel << "is address of data model";
in QML
Code:
property var refToMainModelForC: treeModel
DataModel {
id: treeModel
property var viewCurrentIndex: null
}
Re: How to get Object's pointer instantiated in QML engine
Or the model could register itself inside its C++ code.
Or you call a register function in QML when you want to register a particular model.
Both obviously a lot cleaner than making the C++ code depend in a specific property name on a specific object.
And as always when "the need" to access a QML instantiated object arises: what do you need this for?
Cheers,
_