Using same constants in QML Scripts and C++
Solved
QML and Qt Quick
-
I think, what you're looking for is the QGlobalStatic Class, To access it in QML, you should make it available via
rootContext()->setContextProperty("Name",Instance Pointer);
This this link for more information -
-
@FabQ
To add to what @GPBeta wrote, this requires you to register theConstants
classqmlRegisterType<Constants>("your.module", 0, 1, "Constants");
http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#enumeration-types
-
All solutions revolve around registering the class with QML. You can consider using Q_GADGET, if you don't want to inherit from QObject while exposing constants to QML.