Hi
I don't know how to manage a patch, but if I can show how I solve my
problem.
My property is an enum and to convert a string to that enum, I made
some changes (in red ) in qvariant2qobject.
I don't know if this is interesting for you?
Regards
Jean
void QObjectHelper::qvariant2qobject(const QVariantMap& variant,
QObject* object)
{
const QMetaObject *metaobject = object->metaObject();
QVariantMap::const_iterator iter;
for (iter = variant.constBegin(); iter != variant.constEnd();
++iter) {
int pIdx = metaobject->indexOfProperty( iter.key().toAscii() );
if ( pIdx < 0 ) {
continue;
}
QMetaProperty metaproperty = metaobject->property( pIdx );
QVariant::Type type = metaproperty.type();
QVariant v( iter.value() );
if (metaproperty.isEnumType())
{
QMetaEnum metaEnum = metaproperty.enumerator();
type = QVariant::Int;
v = metaEnum.keyToValue(v.toByteArray().data());
}
if ( v.canConvert( type ) ) {
v.convert( type );
metaproperty.write( object, v );
} else if
(QString(QLatin1String("QVariant")).compare(QLatin1String(metaproperty.t
ypeName())) == 0) {
metaproperty.write( object, v );
}
}
}
My emun
enum eDeviceTypes { Ap3, Ap8, T130, T123, T145, SirAlim, Asc2, PC,
Automate, CallPoint };
My data
{
"Devices": [
{
"Address": 1,
"DeviceType": "T123",
},
{
"Address": 2,
"DeviceType": "Ap8",
}
]
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QJson-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qjson-devel