Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Newbie : pass C++ instances to QML
I would like to know if it is possible to instantiate an object in C++ (which exposes properties with Q_PROPERTY) and to use this object instantiated in C++ in a QML context.
I know that to use a C++ object in QML, I have to use qmlRegisterType but I don't want to do instantiation in QML.
Thanks for your help
ODБOï last edited by
in your particular case:
Thank you, it seems to suit my needs.
Is there an equivalent with qt 5.11 as this method was introduced in qt 5.14 ?
Bob64 last edited by
@sebastienc For older Qt, I think this is what you need:
Your object will be accessible via the global
myobjproperty (or whatever you want to call it) in your QML.
Obviously, your C++ object has to be a
QObjectand have QML-compatible members exposed on it (e.g.
Q_PROPERTYmembers) to be useful.
@Bob64 Perfect !