一、enum 自省
const QMetaObject &mo = [ClassName]::staticMetaObject; int index = mo.indexOfEnumerator("[EnumName]"); QMetaEnum me = mo.enumerator(index);
若 enum 定义在当前类中,则可以简写为
int index = staticMetaObject.indexOfEnumerator("[EnumName]"); QMetaEnum me = staticMetaObject.enumerator(index);
二、enum 转换
1、 enum <-> int
enum Color { Red, White, Blue};Color c = (Color)1; //c=Whiteint i = Red; //i=0
2、 enum <-> string
enum Color { Red, White, Blue};Color c = QString s =
时间: 2024-08-23 07:25:38