I don't know if that helps you in any way but here goes:
Q_OBJECT
public:
enum X {
A, B = 13, C
}
Q_ENUMS(X);
};
Q_DECLARE_METATYPE(Cls::X)
#include "main.moc"
int main(){
int xMT = qRegisterMetaType<Cls::X>("Cls::X");
qDebug() << "Type id:" << xMT;
qDebug() << v;
Cls::X x = v.value<Cls::X>();
qDebug() << x;
QMetaEnum en
= Cls
::staticMetaObject.
enumerator(0);
qDebug() << en.value(0) << en.value(1) << en.value(2);
qDebug() << "Key for Cls::B is:" << en.valueToKey(Cls::B);
qDebug() << "Key for v is:" << en.valueToKey(v.value<Cls::X>());
qDebug() << "Key for v is:" << en.valueToKey(*(int*)v.data());
return 0;
}
class Cls : public QObject {
Q_OBJECT
public:
enum X {
A, B = 13, C
}
Q_ENUMS(X);
};
Q_DECLARE_METATYPE(Cls::X)
#include "main.moc"
int main(){
int xMT = qRegisterMetaType<Cls::X>("Cls::X");
qDebug() << "Type id:" << xMT;
QVariant v = qVariantFromValue(Cls::B);
qDebug() << v;
Cls::X x = v.value<Cls::X>();
qDebug() << x;
QMetaEnum en = Cls::staticMetaObject.enumerator(0);
qDebug() << en.value(0) << en.value(1) << en.value(2);
qDebug() << "Key for Cls::B is:" << en.valueToKey(Cls::B);
qDebug() << "Key for v is:" << en.valueToKey(v.value<Cls::X>());
qDebug() << "Key for v is:" << en.valueToKey(*(int*)v.data());
return 0;
}
To copy to clipboard, switch view to plain text mode
and the output:
Type id: 258
QVariant(Cls::X, )
13
0 13 14
Key for Cls::B is: B
Key for v is: B
Key for v is: B
Type id: 258
QVariant(Cls::X, )
13
0 13 14
Key for Cls::B is: B
Key for v is: B
Key for v is: B
To copy to clipboard, switch view to plain text mode
Bookmarks