diff options
author | Alan Alpert <aalpert@blackberry.com> | 2013-05-15 12:53:11 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-22 19:46:35 +0200 |
commit | 2f988d4b65428d03f3e3fee383787106b3f38c35 (patch) | |
tree | 6eb3c51a103f115f1b69826abe2b196027d7d7c3 /tests | |
parent | 2074386df9ce8a72b6fb2553bb7a5a353964c7b4 (diff) |
Partial fix for deferred properties when combined with components
Current deferred properties implementation did not store context
or compiled data pointers correctly. Those pointers are now stored
when the defer is reached, so as to avoid confusion (confusion leads
to asserts or crashes).
Does not extend the deferred property support to allow multiple
deferred blocks per item. This now prints and error and the side
effect is only that one of the deferred blocks is lost. This use
case is sufficiently rare that it may not be worth the cost.
Task-number: QTBUG-30325
Change-Id: I80cb074ed4452e95020208a0142a91e721bced7d
Reviewed-by: Matthew Vogt <matthew.vogt@qinetic.com.au>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests')
4 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/MyDeferredComponent.qml b/tests/auto/qml/qqmlecmascript/data/MyDeferredComponent.qml new file mode 100644 index 0000000000..1432e7da55 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/MyDeferredComponent.qml @@ -0,0 +1,10 @@ +import Qt.test 1.0 +import QtQml 2.0 + +MyDeferredObject { + id: root + property QtObject target: null + objectProperty: MyQmlObject { + value: target.value + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/MyDeferredComponent2.qml b/tests/auto/qml/qqmlecmascript/data/MyDeferredComponent2.qml new file mode 100644 index 0000000000..de73629f7a --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/MyDeferredComponent2.qml @@ -0,0 +1,3 @@ +import Qt.test 1.0 + +MyDeferredObject {} diff --git a/tests/auto/qml/qqmlecmascript/data/deferredPropertiesInComponents.qml b/tests/auto/qml/qqmlecmascript/data/deferredPropertiesInComponents.qml new file mode 100644 index 0000000000..868b7b1908 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/deferredPropertiesInComponents.qml @@ -0,0 +1,15 @@ +import Qt.test 1.0 +import QtQml 2.0 + +QtObject { + id: root + property int value: 10 + property QtObject deferredInside: MyDeferredComponent { + target: root + } + property QtObject deferredOutside: MyDeferredComponent2 { + objectProperty: MyQmlObject { + value: root.value + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 06590f0ad6..c417879d3c 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -88,6 +88,7 @@ private slots: void objectPropertiesTriggerReeval(); void deferredProperties(); void deferredPropertiesErrors(); + void deferredPropertiesInComponents(); void extensionObjects(); void overrideExtensionProperties(); void attachedProperties(); @@ -865,6 +866,37 @@ void tst_qqmlecmascript::deferredPropertiesErrors() delete object; } +void tst_qqmlecmascript::deferredPropertiesInComponents() +{ + // Test that it works when the property is set inside and outside component + QQmlComponent component(&engine, testFileUrl("deferredPropertiesInComponents.qml")); + QObject *object = component.create(); + if (!object) + qDebug() << component.errorString(); + QVERIFY(object != 0); + QCOMPARE(object->property("value").value<int>(), 10); + + MyDeferredObject *defObjectA = + qobject_cast<MyDeferredObject *>(object->property("deferredInside").value<QObject*>()); + QVERIFY(defObjectA != 0); + QVERIFY(defObjectA->objectProperty() == 0); + + qmlExecuteDeferred(defObjectA); + QVERIFY(defObjectA->objectProperty() != 0); + QCOMPARE(defObjectA->objectProperty()->property("value").value<int>(), 10); + + MyDeferredObject *defObjectB = + qobject_cast<MyDeferredObject *>(object->property("deferredOutside").value<QObject*>()); + QVERIFY(defObjectB != 0); + QVERIFY(defObjectB->objectProperty() == 0); + + qmlExecuteDeferred(defObjectB); + QVERIFY(defObjectB->objectProperty() != 0); + QCOMPARE(defObjectB->objectProperty()->property("value").value<int>(), 10); + + delete object; +} + void tst_qqmlecmascript::extensionObjects() { QQmlComponent component(&engine, testFileUrl("extensionObjects.qml")); |