我在頭文件中註冊了枚舉類型「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