Blame SOURCES/0007-QQuickLoader-Do-not-incubate-if-the-source-arrives-a.patch

77f9a9
From 31179b578276f10841fcb60a876ea757f9ca82ff Mon Sep 17 00:00:00 2001
77f9a9
From: Aleix Pol <aleixpol@kde.org>
77f9a9
Date: Tue, 21 Sep 2021 00:10:26 +0200
77f9a9
Subject: [PATCH 07/20] QQuickLoader: Do not incubate if the source arrives
77f9a9
 after setActive(false)
77f9a9
77f9a9
Otherwise we end up in the crazy place of active being false but item
77f9a9
being non-null and forces us to workaround within the apps.
77f9a9
77f9a9
Change-Id: I88c27c4b00ccec8b8e0c05a8e10b44fcabfc2e30
77f9a9
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
77f9a9
(cherry picked from commit e78c068700fa74ab3aca6a23ab2450563b1c3a5c)
77f9a9
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
77f9a9
---
77f9a9
 src/quick/items/qquickloader.cpp              |  3 +++
77f9a9
 .../data/loader-async-race-rect.qml           | 10 ++++++++++
77f9a9
 .../qquickloader/data/loader-async-race.qml   | 14 ++++++++++++++
77f9a9
 .../quick/qquickloader/tst_qquickloader.cpp   | 19 +++++++++++++++++++
77f9a9
 4 files changed, 46 insertions(+)
77f9a9
 create mode 100644 tests/auto/quick/qquickloader/data/loader-async-race-rect.qml
77f9a9
 create mode 100644 tests/auto/quick/qquickloader/data/loader-async-race.qml
77f9a9
77f9a9
diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp
77f9a9
index cb4f79a3c2..7fbe66fdda 100644
77f9a9
--- a/src/quick/items/qquickloader.cpp
77f9a9
+++ b/src/quick/items/qquickloader.cpp
77f9a9
@@ -737,6 +737,9 @@ void QQuickLoaderPrivate::_q_sourceLoaded()
77f9a9
         return;
77f9a9
     }
77f9a9
 
77f9a9
+    if (!active)
77f9a9
+        return;
77f9a9
+
77f9a9
     QQmlContext *creationContext = component->creationContext();
77f9a9
     if (!creationContext) creationContext = qmlContext(q);
77f9a9
     itemContext = new QQmlContext(creationContext);
77f9a9
diff --git a/tests/auto/quick/qquickloader/data/loader-async-race-rect.qml b/tests/auto/quick/qquickloader/data/loader-async-race-rect.qml
77f9a9
new file mode 100644
77f9a9
index 0000000000..a56dcea5ad
77f9a9
--- /dev/null
77f9a9
+++ b/tests/auto/quick/qquickloader/data/loader-async-race-rect.qml
77f9a9
@@ -0,0 +1,10 @@
77f9a9
+import QtQuick 2.15
77f9a9
+
77f9a9
+Rectangle {
77f9a9
+    anchors.fill: parent
77f9a9
+    color: "blue"
77f9a9
+    Item {
77f9a9
+        Item {
77f9a9
+        }
77f9a9
+    }
77f9a9
+}
77f9a9
diff --git a/tests/auto/quick/qquickloader/data/loader-async-race.qml b/tests/auto/quick/qquickloader/data/loader-async-race.qml
77f9a9
new file mode 100644
77f9a9
index 0000000000..8ba625c5c1
77f9a9
--- /dev/null
77f9a9
+++ b/tests/auto/quick/qquickloader/data/loader-async-race.qml
77f9a9
@@ -0,0 +1,14 @@
77f9a9
+import QtQuick 2.15
77f9a9
+
77f9a9
+Item {
77f9a9
+    id: root
77f9a9
+    Component.onCompleted: {
77f9a9
+        myloader.active = false
77f9a9
+    }
77f9a9
+    Loader {
77f9a9
+        id: myloader
77f9a9
+        anchors.fill: parent
77f9a9
+        asynchronous: true
77f9a9
+        source: "loader-async-race-rect.qml"
77f9a9
+    }
77f9a9
+}
77f9a9
diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
77f9a9
index 0f6c811adb..dddacbaa0b 100644
77f9a9
--- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp
77f9a9
+++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
77f9a9
@@ -132,6 +132,7 @@ private slots:
77f9a9
     void statusChangeOnlyEmittedOnce();
77f9a9
 
77f9a9
     void setSourceAndCheckStatus();
77f9a9
+    void asyncLoaderRace();
77f9a9
 };
77f9a9
 
77f9a9
 Q_DECLARE_METATYPE(QList<QQmlError>)
77f9a9
@@ -1496,6 +1497,24 @@ void tst_QQuickLoader::setSourceAndCheckStatus()
77f9a9
     QCOMPARE(loader->status(), QQuickLoader::Null);
77f9a9
 }
77f9a9
 
77f9a9
+void tst_QQuickLoader::asyncLoaderRace()
77f9a9
+{
77f9a9
+    QQmlApplicationEngine engine;
77f9a9
+    auto url = testFileUrl("loader-async-race.qml");
77f9a9
+    engine.load(url);
77f9a9
+    auto root = engine.rootObjects().at(0);
77f9a9
+    QVERIFY(root);
77f9a9
+
77f9a9
+    QQuickLoader *loader = root->findChild<QQuickLoader *>();
77f9a9
+    QCOMPARE(loader->active(), false);
77f9a9
+    QCOMPARE(loader->status(), QQuickLoader::Null);
77f9a9
+    QCOMPARE(loader->item(), nullptr);
77f9a9
+
77f9a9
+    QSignalSpy spy(loader, &QQuickLoader::itemChanged);
77f9a9
+    QVERIFY(!spy.wait(100));
77f9a9
+    QCOMPARE(loader->item(), nullptr);
77f9a9
+}
77f9a9
+
77f9a9
 QTEST_MAIN(tst_QQuickLoader)
77f9a9
 
77f9a9
 #include "tst_qquickloader.moc"
77f9a9
-- 
77f9a9
2.35.1
77f9a9