You could also make it as follows:
enum MyEnum {MyValue...};
Q_ENUMS(MyEnum);
.
.
.
const QMetaObject &mo
= SetupExporter
::staticMetaObject;
int index = mo.indexOfEnumerator(enumName.toLatin1().constData());
return QString(metaEnum.
valueToKey(value
));
}
.
.
.
settings.setValue(enum2Str(MyValue), MyValue);
enum MyEnum {MyValue...};
Q_ENUMS(MyEnum);
.
.
.
QString enum2Str(MyEnum value, const QString &enumName = "MyEnum") {
const QMetaObject &mo = SetupExporter::staticMetaObject;
int index = mo.indexOfEnumerator(enumName.toLatin1().constData());
QMetaEnum metaEnum = mo.enumerator(index);
return QString(metaEnum.valueToKey(value));
}
.
.
.
QSettings settings("test.ini", QSettings::IniFormat);
settings.setValue(enum2Str(MyValue), MyValue);
To copy to clipboard, switch view to plain text mode
Regards
NoRulez
Bookmarks