aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang Chuan <ouchuanm@outlook.com>2020-08-15 15:26:51 +0800
committerWang Chuan <ouchuanm@outlook.com>2020-08-25 21:46:44 +0800
commit52f95ff0bdab6bd74067b0ad001a4a6707e06e0e (patch)
tree6c6352eaec8b1fc1aafa74fbb1626fde40494fd8
parentd535b85a84ee89530a80b606701910a90681bdce (diff)
QQuickLoader: make sure the status property change properly
When we call [setSource] in qml, we will try to convert a qml value to a string which indicate the url we want to load. However, if this value is undefined, it will convert to a string with content "undefined", and then cause loading error. More worse, if there is a qml file named "undefined", it will be loaded to the Loader. Fixes: QTBUG-85938 Change-Id: I5b192ba84aa29532e547349bbf37d413c107d8e4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 3d195d33ece3f8fd7cd7d8e6163fe038fc7fc036)
-rw-r--r--src/quick/items/qquickloader.cpp2
-rw-r--r--tests/auto/quick/qquickloader/tst_qquickloader.cpp3
2 files changed, 5 insertions, 0 deletions
diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp
index e961617505..8cd63a4236 100644
--- a/src/quick/items/qquickloader.cpp
+++ b/src/quick/items/qquickloader.cpp
@@ -968,6 +968,8 @@ QUrl QQuickLoaderPrivate::resolveSourceUrl(QQmlV4Function *args)
{
QV4::Scope scope(args->v4engine());
QV4::ScopedValue v(scope, (*args)[0]);
+ if (v->isUndefined())
+ return QUrl();
QString arg = v->toQString();
if (arg.isEmpty())
return QUrl();
diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
index 91b42690cd..f4b682f3f4 100644
--- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp
+++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
@@ -1486,6 +1486,9 @@ void tst_QQuickLoader::setSourceAndCheckStatus()
QMetaObject::invokeMethod(loader, "load", Q_ARG(QVariant, QVariant::fromValue(QStringLiteral(""))));
QCOMPARE(loader->status(), QQuickLoader::Null);
+
+ QMetaObject::invokeMethod(loader, "load", Q_ARG(QVariant, QVariant()));
+ QCOMPARE(loader->status(), QQuickLoader::Null);
}
QTEST_MAIN(tst_QQuickLoader)