diff options
author | Wang Chuan <ouchuanm@outlook.com> | 2020-08-15 14:57:06 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-08-25 03:24:48 +0000 |
commit | d535b85a84ee89530a80b606701910a90681bdce (patch) | |
tree | b8ff528f076364ee5cdcace1a2dc70791b9852ed /tests | |
parent | 9ca1ebf9d1d5b8c34ac1148740567b77d629b85e (diff) |
QQuickLoader: make sure the status property change properly
Since the invocation of [setSource] in qml will clear the old source url
first, it is hard to decide whether we have changed the source url,
especially when we call [setSource] with an empty string, and the loader's
status won't change properly.
Fixes: QTBUG-85938
Change-Id: If61a33c790a4fd6562611c4c50756bc5e213363a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 3aa4cd682f52b70803cc3f72d732bde9987677dd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickloader/data/setSourceAndCheckStatus.qml | 14 | ||||
-rw-r--r-- | tests/auto/quick/qquickloader/tst_qquickloader.cpp | 18 |
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickloader/data/setSourceAndCheckStatus.qml b/tests/auto/quick/qquickloader/data/setSourceAndCheckStatus.qml new file mode 100644 index 0000000000..70779047aa --- /dev/null +++ b/tests/auto/quick/qquickloader/data/setSourceAndCheckStatus.qml @@ -0,0 +1,14 @@ +import QtQuick 2.12 +import QtQuick.Window 2.12 + +Window { + id: root + visible: true; width: 640; height: 480 + Loader { + id: loader + anchors.fill: parent + function load(url) { + loader.setSource(url) + } + } +} diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index 91d0bcab2e..91b42690cd 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -130,6 +130,8 @@ private slots: void sourceURLKeepComponent(); void statusChangeOnlyEmittedOnce(); + + void setSourceAndCheckStatus(); }; Q_DECLARE_METATYPE(QList<QQmlError>) @@ -1470,6 +1472,22 @@ void tst_QQuickLoader::statusChangeOnlyEmittedOnce() QCOMPARE(root->property("statusChangedCounter").toInt(), 2); // 1xLoading + 1xReady*/ } +void tst_QQuickLoader::setSourceAndCheckStatus() +{ + QQmlApplicationEngine engine; + auto url = testFileUrl("setSourceAndCheckStatus.qml"); + engine.load(url); + auto root = engine.rootObjects().at(0); + QVERIFY(root); + + QQuickLoader *loader = root->findChild<QQuickLoader *>(); + QMetaObject::invokeMethod(loader, "load", Q_ARG(QVariant, QVariant::fromValue(QStringLiteral("./RedRect.qml")))); + QCOMPARE(loader->status(), QQuickLoader::Ready); + + QMetaObject::invokeMethod(loader, "load", Q_ARG(QVariant, QVariant::fromValue(QStringLiteral("")))); + QCOMPARE(loader->status(), QQuickLoader::Null); +} + QTEST_MAIN(tst_QQuickLoader) #include "tst_qquickloader.moc" |