我在头文件中注册了一个枚举类型"ClefType" - 这个枚举使用Q_DECLARE_METATYPE和Q_ENUMS宏在MetaObject系统中注册.qRegisterMetaType也在类构造函数中调用.
这允许我在Q_PROPERTY中使用这种类型,这一切都正常.但是,稍后,我需要能够在给定对象的情况下获得此枚举类型的Q_PROPERTY - 以适合序列化的形式.
理想情况下,存储该枚举成员的整数值会很有用,因为我不希望它特定于所使用的枚举类型 - 最终我希望有几个不同的枚举.
// This is inside a loop over all the properties on a given object
QMetaProperty property = metaObject->property(propertyId);
QString propertyName = propertyMeta.name();
QVariant variantValue = propertyMeta.read(serializeObject);
// If, internally, this QVariant is of type 'ClefType',
// how do I pull out the integer value for this enum?
Run Code Online (Sandbox Code Playgroud)
遗憾的是variantValue.toInt();不起作用 - 自定义枚举似乎不能直接"转换"为整数值.
提前致谢,
亨利
qt4 ×1