QQuickLoader: do not incubate if the source arrives after setActive(false)
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Thu, 29 Sep 2022 08:39:46 +0000 (09:39 +0100)
committerDmitry Shachnev <mitya57@debian.org>
Thu, 29 Sep 2022 08:39:46 +0000 (09:39 +0100)
Origin: upstream, https://code.qt.io/cgit/qt/qtdeclarative.git/commit/?id=e78c068700fa74ab
Last-Update: 2022-07-01

Otherwise we end up in the crazy place of active being false but item
being non-null and forces us to workaround within the apps.

Gbp-Pq: Name QQuickLoader-Do-not-incubate-if-the-source-arrives-a.patch

src/quick/items/qquickloader.cpp
tests/auto/quick/qquickloader/data/loader-async-race-rect.qml [new file with mode: 0644]
tests/auto/quick/qquickloader/data/loader-async-race.qml [new file with mode: 0644]
tests/auto/quick/qquickloader/tst_qquickloader.cpp

index cb4f79a3c2a1416b33043288e0996b17a1bcc63f..7fbe66fdda9e7f1500b7b9461fcfd4524b295eee 100644 (file)
@@ -737,6 +737,9 @@ void QQuickLoaderPrivate::_q_sourceLoaded()
         return;
     }
 
+    if (!active)
+        return;
+
     QQmlContext *creationContext = component->creationContext();
     if (!creationContext) creationContext = qmlContext(q);
     itemContext = new QQmlContext(creationContext);
diff --git a/tests/auto/quick/qquickloader/data/loader-async-race-rect.qml b/tests/auto/quick/qquickloader/data/loader-async-race-rect.qml
new file mode 100644 (file)
index 0000000..a56dcea
--- /dev/null
@@ -0,0 +1,10 @@
+import QtQuick 2.15
+
+Rectangle {
+    anchors.fill: parent
+    color: "blue"
+    Item {
+        Item {
+        }
+    }
+}
diff --git a/tests/auto/quick/qquickloader/data/loader-async-race.qml b/tests/auto/quick/qquickloader/data/loader-async-race.qml
new file mode 100644 (file)
index 0000000..8ba625c
--- /dev/null
@@ -0,0 +1,14 @@
+import QtQuick 2.15
+
+Item {
+    id: root
+    Component.onCompleted: {
+        myloader.active = false
+    }
+    Loader {
+        id: myloader
+        anchors.fill: parent
+        asynchronous: true
+        source: "loader-async-race-rect.qml"
+    }
+}
index 0f6c811adba6a6b6e62634e6c0d926354aa09777..dddacbaa0b3621b524d550d43df25bcf63340396 100644 (file)
@@ -132,6 +132,7 @@ private slots:
     void statusChangeOnlyEmittedOnce();
 
     void setSourceAndCheckStatus();
+    void asyncLoaderRace();
 };
 
 Q_DECLARE_METATYPE(QList<QQmlError>)
@@ -1496,6 +1497,24 @@ void tst_QQuickLoader::setSourceAndCheckStatus()
     QCOMPARE(loader->status(), QQuickLoader::Null);
 }
 
+void tst_QQuickLoader::asyncLoaderRace()
+{
+    QQmlApplicationEngine engine;
+    auto url = testFileUrl("loader-async-race.qml");
+    engine.load(url);
+    auto root = engine.rootObjects().at(0);
+    QVERIFY(root);
+
+    QQuickLoader *loader = root->findChild<QQuickLoader *>();
+    QCOMPARE(loader->active(), false);
+    QCOMPARE(loader->status(), QQuickLoader::Null);
+    QCOMPARE(loader->item(), nullptr);
+
+    QSignalSpy spy(loader, &QQuickLoader::itemChanged);
+    QVERIFY(!spy.wait(100));
+    QCOMPARE(loader->item(), nullptr);
+}
+
 QTEST_MAIN(tst_QQuickLoader)
 
 #include "tst_qquickloader.moc"