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)
For the global Enum declaring use this in any header file:
namespace YourNamespace {
Q_NAMESPACE
enum YourEnum: int {
EnumValue1,
EnumValue2
};
Q_ENUM_NS(YourEnum)
}
and this where you want to get Enum description:
QMetaEnum metaEnum = QMetaEnum::fromType();
qDebug() << "Enum description: " << metaEnum.name() << "::" << metaEnum.valueToKey(YourEnum::EnumValue2);