diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-05-21 16:11:24 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-27 07:53:24 +0200 |
commit | 228fe20d82c15b713f773b5cfc33910d3457fb63 (patch) | |
tree | 717e9f29f45498597e0c6ee6ac90fc1036b4c941 | |
parent | 7a5f70d6e5037334813db938eb0f4a646df512e9 (diff) |
Fix crash (failing assertion) when declaring a non-string id property
This isn't very useful QML, but the following was "legal" in 5.1:
property int id:
id: foo
The integer property was not set, but the object's name (id) was still set.
With 5.3 this causes a failing assertion, which shouldn't happen. We should
do the same thing as the old code in QQmlComponent::buildProperty did for
id properties: Set them only if they're of string type.
Task-number: QTBUG-38463
Change-Id: I0da58557fbfb0944f53127e0ee77117ac33ce250
Reviewed-by: Tasuku Suzuki <stasuku@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-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 |