我在头文件中注册了枚举类型“ClefType” - 此枚举使用Q_DECLARE_METATYPE和Q_ENUMS宏在MetaObject系统中注册。 qRegisterMetaType也在类构造函数中调用。访问存储在QVariant中的枚举
这使我可以在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?
不幸的是variantValue.toInt();
不起作用 - 自定义枚举似乎没有直接“浇注料”为整数值。
由于提前,
亨利
效果很好 - 非常感谢您的深入响应!非常感激 – 2010-04-07 10:06:53