Access enums defined in non-Qt C++ class.
-
I have a plain C++ defined with enums like
class MyEnums
{
enum someEnum
{
VAL1,
VAL2,
....
}
};I want to use this enum in my QML. Any thoughts how to acheive this?
Note: This is not a class having Q_OBJECT, Q_NAMESPACE or Q_GADGET and not inherited from QObject.
-
You need to use Qt facilities to expose them to QML, the same as if you wanted to call a C++ function from QML. If you are unable to modify the existing C++ code, I would suggest introducing a new Qt-based enum type that mirrors your existing type, expose that to QML, and convert between the two types somewhere appropriate in your backend code.