diff options
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/idPropertyMismatch.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 39 |
3 files changed, 31 insertions, 15 deletions
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 2ebf90c9be..a8eeeeeddd 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -651,7 +651,7 @@ void QQmlObjectCreator::setupBindings(const QBitArray &bindingsToSkip) QString id = stringAt(_compiledObject->idIndex); if (!id.isEmpty()) { QQmlPropertyData *idProperty = _propertyCache->property(QStringLiteral("id"), _qobject, context); - if (idProperty && idProperty->isWritable()) { + if (idProperty && idProperty->isWritable() && idProperty->propType == QMetaType::QString) { QV4::CompiledData::Binding idBinding; idBinding.propertyNameIndex = 0; // Not used idBinding.flags = 0; diff --git a/tests/auto/qml/qqmllanguage/data/idPropertyMismatch.qml b/tests/auto/qml/qqmllanguage/data/idPropertyMismatch.qml new file mode 100644 index 0000000000..8c4fd65786 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/idPropertyMismatch.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 +QtObject { + property int id; + id: "root" +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 2ade0b2652..95d6eb9262 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -1201,21 +1201,32 @@ void tst_qqmllanguage::inlineQmlComponents() // Tests that types that have an id property have it set void tst_qqmllanguage::idProperty() { - QQmlComponent component(&engine, testFileUrl("idProperty.qml")); - VERIFY_ERRORS(0); - MyContainer *object = qobject_cast<MyContainer *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->getChildren()->count(), 2); - MyTypeObject *child = - qobject_cast<MyTypeObject *>(object->getChildren()->at(0)); - QVERIFY(child != 0); - QCOMPARE(child->id(), QString("myObjectId")); - QCOMPARE(object->property("object"), QVariant::fromValue((QObject *)child)); + { + QQmlComponent component(&engine, testFileUrl("idProperty.qml")); + VERIFY_ERRORS(0); + MyContainer *object = qobject_cast<MyContainer *>(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->getChildren()->count(), 2); + MyTypeObject *child = + qobject_cast<MyTypeObject *>(object->getChildren()->at(0)); + QVERIFY(child != 0); + QCOMPARE(child->id(), QString("myObjectId")); + QCOMPARE(object->property("object"), QVariant::fromValue((QObject *)child)); - child = - qobject_cast<MyTypeObject *>(object->getChildren()->at(1)); - QVERIFY(child != 0); - QCOMPARE(child->id(), QString("name.with.dots")); + child = + qobject_cast<MyTypeObject *>(object->getChildren()->at(1)); + QVERIFY(child != 0); + QCOMPARE(child->id(), QString("name.with.dots")); + } + { + QQmlComponent component(&engine, testFileUrl("idPropertyMismatch.qml")); + VERIFY_ERRORS(0); + QScopedPointer<QObject> root(component.create()); + QVERIFY(!root.isNull()); + QQmlContext *ctx = qmlContext(root.data()); + QVERIFY(ctx); + QCOMPARE(ctx->nameForObject(root.data()), QString("root")); + } } // Tests automatic connection to notify signals if "onBlahChanged" syntax is used |