aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllanguage
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-05-21 16:11:24 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-27 07:53:24 +0200
commit228fe20d82c15b713f773b5cfc33910d3457fb63 (patch)
tree717e9f29f45498597e0c6ee6ac90fc1036b4c941 /tests/auto/qml/qqmllanguage
parent7a5f70d6e5037334813db938eb0f4a646df512e9 (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>
Diffstat (limited to 'tests/auto/qml/qqmllanguage')
-rw-r--r--tests/auto/qml/qqmllanguage/data/idPropertyMismatch.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp39
2 files changed, 30 insertions, 14 deletions
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