aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-12-04 14:06:59 +0100
committerUlf Hermann <ulf.hermann@qt.io>2018-12-12 09:03:56 +0000
commit1d88e9919ff837d535f9bbde53613b6a6b96fcd8 (patch)
tree759b83dcbcff472837c41872b70e7a7ba1ba4c86 /tests
parente3446c8225acbaa6a613d6c62e8e2fc58e2b70b0 (diff)
QML: Fix registering and unregistering of context objects
When we add a context object we need to include it into the list of contextObjects of its outer context, so that the outerContext member can be reset when the outer context disappears. On the flip side, we also need to remove it from this list when the object gets removed. We don't need to reset the inner context of an object when the outer context disappears, though. Fixes: QTBUG-72241 Change-Id: Ifd34650d852642a364df23b697d32e3961d0479b Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlcontext/data/Drawer.qml6
-rw-r--r--tests/auto/qml/qqmlcontext/data/contextObjectHierarchy.qml6
-rw-r--r--tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp19
3 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcontext/data/Drawer.qml b/tests/auto/qml/qqmlcontext/data/Drawer.qml
new file mode 100644
index 0000000000..b35d5c8d34
--- /dev/null
+++ b/tests/auto/qml/qqmlcontext/data/Drawer.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.12
+import QtQuick.Window 2.11
+
+Rectangle {
+ parent: Window.contentItem
+}
diff --git a/tests/auto/qml/qqmlcontext/data/contextObjectHierarchy.qml b/tests/auto/qml/qqmlcontext/data/contextObjectHierarchy.qml
new file mode 100644
index 0000000000..91978d98a0
--- /dev/null
+++ b/tests/auto/qml/qqmlcontext/data/contextObjectHierarchy.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.6
+import QtQuick.Window 2.2
+
+Window {
+ Drawer {}
+}
diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
index 5838193a6b..89640bc385 100644
--- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
+++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
@@ -70,6 +70,7 @@ private slots:
void contextLeak();
void outerContextObject();
+ void contextObjectHierarchy();
private:
QQmlEngine engine;
@@ -873,6 +874,24 @@ void tst_qqmlcontext::outerContextObject()
QTRY_VERIFY(iterations >= 100);
}
+void tst_qqmlcontext::contextObjectHierarchy()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("contextObjectHierarchy.qml"));
+ QVERIFY(component.isReady());
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY(!root.isNull());
+
+ for (const QObject *child : root->children()) {
+ QQmlData *d = QQmlData::get(child);
+ QVERIFY(d->outerContext != nullptr);
+ connect(root.data(), &QObject::destroyed, [&]() {
+ QCOMPARE(d->outerContext, nullptr);
+ });
+ }
+}
+
QTEST_MAIN(tst_qqmlcontext)
#include "tst_qqmlcontext.moc"