From 9ab7e2356e9d698a378e85b511269784c9f06828 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 1 Apr 2015 23:38:32 +0200 Subject: [PATCH] Use QMetaObject for introspecting a QObject It will be faster and will provide better error messages. REVIEW: 123214 --- core/networkpackage.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core/networkpackage.cpp b/core/networkpackage.cpp index 6f7e62e44..452977ed8 100644 --- a/core/networkpackage.cpp +++ b/core/networkpackage.cpp @@ -111,18 +111,16 @@ void qvariant2qobject(const QVariantMap& variant, QObject* object) { for ( QVariantMap::const_iterator iter = variant.begin(); iter != variant.end(); ++iter ) { - QVariant property = object->property( iter.key().toLatin1() ); - Q_ASSERT( property.isValid() ); - if ( property.isValid() ) - { - QVariant value = iter.value(); - if ( value.canConvert( property.type() ) ) - { - value.convert( property.type() ); - object->setProperty( iter.key().toLatin1(), value ); - } else if ( QString( QLatin1String("QVariant") ).compare( QLatin1String( property.typeName() ) ) == 0) { - object->setProperty( iter.key().toLatin1(), value ); - } + const int propertyIndex = object->metaObject()->indexOfProperty(iter.key().toLatin1()); + if (propertyIndex < 0) { + qCWarning(KDECONNECT_CORE) << "missing property" << object << iter.key(); + continue; + } + + QMetaProperty property = object->metaObject()->property(propertyIndex); + bool ret = property.write(object, *iter); + if (!ret) { + qCWarning(KDECONNECT_CORE) << "couldn't set" << object << "->" << property.name() << '=' << *iter; } } }