I am trying to use the Qt reflection for converting enum to QString.
Here is the part of code:
class ModelApple
{
Q_GADGET
Q_ENUMS(AppleType)
The following should get you going:
QString convertEnumToQString(ModelApple::AppleType type) {
const QMetaObject metaObject = ModelApple::staticMetaObject;
int enumIndex = metaObject.indexOfEnumerator("AppleType");
if(enumIndex == -1) {
/* The enum does not contain the specified enum */
return "";
}
QMetaEnum en = metaObject.enumerator(enumIndex);
return QString(en.valueToKey(type));
}