How to import an existing (singleton) c++ object to QML?
-
Hi Qt Forum,
I'm trying to import an existing c++ object to QML. In main.cpp:
Backend backend; QQmlApplicationEngine engine; engine.setInitialProperties({ { "backend", QVariant::fromValue(&backend) } });
In backend.h:
class Backend : public QObject { Q_OBJECT QML_ELEMENT QML_SINGLETON
It's not working:
QQmlApplicationEngine failed to create component qrc:qml/main.qml: Setting initial properties failed: ApplicationWindow does not have a property called backend
Do I need to implement this?:
static Backend* create(QQmlEngine*, QJSEngine*);
if engine is not going to instantiate it?