Qt 中Enum进行反射来做Enum to QString

i assume you want to retrieve a QMetaEnum for a particular enum which is registered with Q_ENUMS.

let {class} denote the QObject-derived class which contains the enum, and let {enumName} denote the name of the enum. the following code gets you the enum's QMetaEnum:

QMetaObject metaObject = {class}.staticMetaObject;
QMetaEnum metaEnum = metaObject.enumerator( metaObject.indexOfEnumerator( {enumName} ) );

this compiles despite the fact that neither QMetaObject nor QMetaEnum define operator=(). i'm not sure why--they must be defined somewhere else, but i can't find them.

原文地址:https://www.cnblogs.com/loning/p/1887125.html