diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-15 17:53:16 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-22 18:37:52 +0200 |
commit | 0a1e4cc7ec7548f6273befff9cdddb0bc7a58961 (patch) | |
tree | bf8b7ae725ac332fa59bd9058cc479018aca147d /src/quick/util | |
parent | 4e266103ad8b75d71fb176a2f774faf71997123d (diff) |
Do not resolve URLs when assigning them to a property
We don't know in advance if a URL is part of the source code and should
be relative to the current element, or if it is part of the application
data and should not be touched.
[ChangeLog][QtQml][Important Behavior Changes] URLs are not resolved or
intercepted anymore when assigning them to a "url" property. Instead
they are resolved and possibly intercepted when used to access an actual
resource.
Fixes: QTBUG-76879
Change-Id: Iaa2385aff2c13aa71a12e57385d9afb5dc60a073
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/quick/util')
-rw-r--r-- | src/quick/util/qquickfontloader.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/quick/util/qquickfontloader.cpp b/src/quick/util/qquickfontloader.cpp index e672fb8510..c27ed25d41 100644 --- a/src/quick/util/qquickfontloader.cpp +++ b/src/quick/util/qquickfontloader.cpp @@ -247,24 +247,27 @@ void QQuickFontLoader::setSource(const QUrl &url) d->url = url; emit sourceChanged(); - QString localFile = QQmlFile::urlToLocalFileOrQrc(d->url); + const QQmlContext *context = qmlContext(this); + const QUrl &resolvedUrl = context ? context->resolvedUrl(d->url) : d->url; + QString localFile = QQmlFile::urlToLocalFileOrQrc(resolvedUrl); if (!localFile.isEmpty()) { - if (!fontLoaderFonts()->map.contains(d->url)) { + if (!fontLoaderFonts()->map.contains(resolvedUrl)) { int id = QFontDatabase::addApplicationFont(localFile); updateFontInfo(id); if (id != -1) { QQuickFontObject *fo = new QQuickFontObject(id); - fontLoaderFonts()->map[d->url] = fo; + fontLoaderFonts()->map[resolvedUrl] = fo; } } else { - updateFontInfo(fontLoaderFonts()->map.value(d->url)->id); + updateFontInfo(fontLoaderFonts()->map.value(resolvedUrl)->id); } } else { - if (!fontLoaderFonts()->map.contains(d->url)) { + if (!fontLoaderFonts()->map.contains(resolvedUrl)) { + Q_ASSERT(context); #if QT_CONFIG(qml_network) QQuickFontObject *fo = new QQuickFontObject; - fontLoaderFonts()->map[d->url] = fo; - fo->download(d->url, qmlEngine(this)->networkAccessManager()); + fontLoaderFonts()->map[resolvedUrl] = fo; + fo->download(resolvedUrl, context->engine()->networkAccessManager()); d->status = Loading; emit statusChanged(); QObject::connect(fo, SIGNAL(fontDownloaded(int)), @@ -273,7 +276,7 @@ void QQuickFontLoader::setSource(const QUrl &url) // Silently fail if compiled with no_network #endif } else { - QQuickFontObject *fo = fontLoaderFonts()->map.value(d->url); + QQuickFontObject *fo = fontLoaderFonts()->map.value(resolvedUrl); if (fo->id == -1) { #if QT_CONFIG(qml_network) d->status = Loading; @@ -321,8 +324,11 @@ void QQuickFontLoader::updateFontInfo(int id) } if (status != d->status) { - if (status == Error) - qmlWarning(this) << "Cannot load font: \"" << d->url.toString() << '"'; + if (status == Error) { + const QQmlContext *context = qmlContext(this); + qmlWarning(this) << "Cannot load font: \"" + << (context ? context->resolvedUrl(d->url) : d->url).toString() << '"'; + } d->status = status; emit statusChanged(); } |