Set object to context:
.... QQmlContext * context = new QQmlContext(engine.rootContext()); context->setContextProperty("data", &data); QQmlComponent component(&engine, QUrl(strQmlPath)); ....
But when used in qml for some reason, it gives the error reference error: data is not defined
:
Item { Connections { target: data onNewMessagePosted: window.visible = false } }
How to push a c ++ object in qml
?
UPD: the class itself is the simplest example
class MessageBoard : public QObject { Q_OBJECT public: void callMe () { emit newMessagePosted (); } ; signals: void newMessagePosted (); };