diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-03-27 14:58:19 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-28 04:35:52 +0200 |
commit | 4d3ccce54a5e58bab878170b1552acd0d4a20cec (patch) | |
tree | 102740e5a9bc144a5dd1c9e8fb2483e6ed2b6b25 /src/qml/qml/qqmlproperty.cpp | |
parent | 0ad4550ac0946540f2c76008765d69c62adeed54 (diff) |
Warn on incompatible v4 binding object type
For QObject-derived properties, verify that the type of the source
object is convertible to the type of the target object, and report
an error for incompatible assignment attempts.
Task-number: QTBUG-24986
Change-Id: Ieece29a017222e48351cd433c1b2f9e2d93a5fd7
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 2d459421d9..b798215fa5 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -1521,13 +1521,28 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object, return true; const char *valueType = 0; - if (value.userType() == QVariant::Invalid) valueType = "null"; - else valueType = QMetaType::typeName(value.userType()); + const char *propertyType = 0; + + if (value.userType() == QMetaType::QObjectStar) { + if (QObject *o = *(QObject **)value.constData()) { + valueType = o->metaObject()->className(); + + const QMetaObject *propertyMetaObject = rawMetaObjectForType(QQmlEnginePrivate::get(engine), type); + propertyType = propertyMetaObject->className(); + } + } else if (value.userType() != QVariant::Invalid) { + valueType = QMetaType::typeName(value.userType()); + } + + if (!valueType) + valueType = "null"; + if (!propertyType) + propertyType = QMetaType::typeName(type); expression->delayedError()->error.setDescription(QLatin1String("Unable to assign ") + QLatin1String(valueType) + QLatin1String(" to ") + - QLatin1String(QMetaType::typeName(type))); + QLatin1String(propertyType)); return false; } |