Do not crash on invalid binding diagnostic
authorMatthew Vogt <matthew.vogt@nokia.com>
Wed, 4 Apr 2012 03:54:29 +0000 (13:54 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 4 Apr 2012 06:43:50 +0000 (08:43 +0200)
If there is no meta object for the property type of the recipient of
an invalid binding, fall back to QMetaType::typename().

Task-number: QTBUG-25161
Change-Id: I0bb768cbc166c04f62d20d8bb19e6ae883d7dc2f
Reviewed-by: Chris Adams <christopher.adams@nokia.com>

src/qml/qml/qqmlproperty.cpp
tests/auto/qml/qqmlproperty/data/invalidBinding.qml
tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp

index 88223dd..e010fd5 100644 (file)
@@ -1522,8 +1522,9 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
             if (QObject *o = *(QObject **)value.constData()) {
                 valueType = o->metaObject()->className();
 
-                const QMetaObject *propertyMetaObject = rawMetaObjectForType(QQmlEnginePrivate::get(engine), type);
-                propertyType = propertyMetaObject->className();
+                if (const QMetaObject *propertyMetaObject = rawMetaObjectForType(QQmlEnginePrivate::get(engine), type)) {
+                    propertyType = propertyMetaObject->className();
+                }
             }
         } else if (value.userType() != QVariant::Invalid) {
             valueType = QMetaType::typeName(value.userType());
index 35dacf1..e2bb1d1 100644 (file)
@@ -10,5 +10,7 @@ Item {
 
     Text {
         id: myText
+
+        anchors.verticalCenter: parent // invalid binding
     }
 }
index 23f7c34..5d7485c 100644 (file)
@@ -1736,6 +1736,10 @@ void tst_qqmlproperty::warnOnInvalidBinding()
     expectedWarning = testUrl.toString() + QString::fromLatin1(":7:36: Unable to assign QQuickText to QQuickRectangle");
     QTest::ignoreMessage(QtWarningMsg, expectedWarning.toLatin1().constData());
 
+    // V8 error message for invalid binding to anchor
+    expectedWarning = testUrl.toString() + QString::fromLatin1(":14: Unable to assign QQuickItem_QML_7 to QQuickAnchorLine");
+    QTest::ignoreMessage(QtWarningMsg, expectedWarning.toLatin1().constData());
+
     QQmlComponent component(&engine, testUrl);
     QObject *obj = component.create();
     QVERIFY(obj);