From 52f95ff0bdab6bd74067b0ad001a4a6707e06e0e Mon Sep 17 00:00:00 2001 From: Wang Chuan Date: Sat, 15 Aug 2020 15:26:51 +0800 Subject: 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 (cherry picked from commit 3d195d33ece3f8fd7cd7d8e6163fe038fc7fc036) --- src/quick/items/qquickloader.cpp | 2 ++ tests/auto/quick/qquickloader/tst_qquickloader.cpp | 3 +++ 2 files changed, 5 insertions(+) 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) -- cgit v1.2.3