From 3aa4cd682f52b70803cc3f72d732bde9987677dd Mon Sep 17 00:00:00 2001 From: Wang Chuan Date: Sat, 15 Aug 2020 14:57:06 +0800 Subject: 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. Pick-to: 5.15 Fixes: QTBUG-85938 Change-Id: If61a33c790a4fd6562611c4c50756bc5e213363a Reviewed-by: Fabian Kosmale --- src/quick/items/qquickloader.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/quick/items/qquickloader.cpp') diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp index 0d47931063..f1e70c14f4 100644 --- a/src/quick/items/qquickloader.cpp +++ b/src/quick/items/qquickloader.cpp @@ -588,8 +588,15 @@ void QQuickLoader::setSource(QQmlV4Function *args) if (ipvError) return; + // 1. If setSource is called with a valid url, clear the old component and its corresponding url + // 2. If setSource is called with an invalid url(e.g. empty url), clear the old component but + // hold the url for old one.(we will compare it with new url later and may update status of loader to Loader.Null) + QUrl oldUrl = d->source; d->clear(); QUrl sourceUrl = d->resolveSourceUrl(args); + if (!sourceUrl.isValid()) + d->source = oldUrl; + d->disposeInitialPropertyValues(); if (!ipv->isUndefined()) { d->initialPropertyValues.set(args->v4engine(), ipv); -- cgit v1.2.3