c++ enum in QML print as string
Solved
QML and Qt Quick
-
Hi;
I need to print "ChQuDefaults.EChTest.ChTest (666)" to "ChQuDefaults.EChTest.ChTest (ChTest)" .
I already tried as ChQuDefaults.EChTest.ChTest.toString() but always print "666".enum defined as in c++;
class CChQuDefaults : public QObject {
Q_OBJECTQML_VALUE_TYPE(ChQuDefaults) QML_ADDED_IN_VERSION(1,0) QML_SINGLETON public: enum class EChTest : qint32 { ChTest = 666 }; Q_ENUM( EChTest) // ...
};
Thanks...
-
Enums in QML always print their value. If you want to print the text, use QMetaEnum in C++.
-
Enums in QML always print their value. If you want to print the text, use QMetaEnum in C++.
-
QString result = QMetaEnum::fromType<EChTest>().valueToKey(int(EChTest::ChTest));
Put it in some Q_INVOKABLE or slot and you will be able to call it from QML.
-
QString result = QMetaEnum::fromType<EChTest>().valueToKey(int(EChTest::ChTest));
Put it in some Q_INVOKABLE or slot and you will be able to call it from QML.