Using c++ enum in QML as string
问题 What I would like to do is use the below enum in c++: class MyClass : public QQuickItem { Q_OBJECT Q_PROPERTY(MyEnum enumValue READ getEnumValue) public: enum MyEnum{ MyEnumElement = 0 }; Q_ENUM(MyEnum) slots: MyEnum getEnumValue(){ return enumValue; } private: MyEnum enumValue = MyEnumElement; }; In such a way in QML: MyClass { id: myClass } Text { text: "enumValue is: " + myClass.enumValue } That would result in enumValue is MyEnumElement instead of enumValue is 0 which is the case now. The