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/items/qquicksprite.cpp | |
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/items/qquicksprite.cpp')
-rw-r--r-- | src/quick/items/qquicksprite.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/quick/items/qquicksprite.cpp b/src/quick/items/qquicksprite.cpp index 58f3de8b7b..28ec8f41e4 100644 --- a/src/quick/items/qquicksprite.cpp +++ b/src/quick/items/qquicksprite.cpp @@ -40,6 +40,7 @@ #include "qquicksprite_p.h" #include "qquickimagebase_p.h" #include <qqml.h> +#include <QQmlContext> #include <QDebug> #include <QRandomGenerator> @@ -261,14 +262,18 @@ void QQuickSprite::startImageLoading() { m_pix.clear(this); if (!m_source.isEmpty()) { - QQmlEngine *e = qmlEngine(this); + const QQmlContext *context = qmlContext(this); + QQmlEngine *e = context ? context->engine() : nullptr; if (!e) { //If not created in QML, you must set the QObject parent to the QML element so this can work - e = qmlEngine(parent()); + context = qmlContext(parent()); + e = context ? context->engine() : nullptr; if (!e) qWarning() << "QQuickSprite: Cannot find QQmlEngine - this class is only for use in QML and may not work"; } - QUrl loadUrl = m_source; - QQuickImageBase::resolve2xLocalFile(m_source, m_devicePixelRatio, &loadUrl, &m_devicePixelRatio); + const QUrl resolvedUrl = context ? context->resolvedUrl(m_source) : m_source; + QUrl loadUrl = resolvedUrl; + QQuickImageBase::resolve2xLocalFile(resolvedUrl, m_devicePixelRatio, &loadUrl, + &m_devicePixelRatio); m_pix.load(e, loadUrl); } |