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

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