aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-08-26 14:30:20 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2020-09-01 11:31:19 +0000
commit47ff10532ebd6c7b0cb62c46b0be3b3d7f6214b8 (patch)
treeece6677fbc033866981041f8fdcb487aacc4272a
parentd40791d6add8937275ecce2d26870c1ef6b6e698 (diff)
QQuickImageProvider: Remove reliance on RTTI
Using staticCast is unsafe, because in theory you can derive from QQmlImageProviderBase instead of QQuickImageProvider. But using dynamicCast runs into issues, because while Qt needs to be compiled with RTTI, user code does not. We thus turn the baseclass into a QObject so that qobject_cast does work. Fixes: QTBUG-84127 Change-Id: Id40d8a13eaa0101d80bd5742a23996354d70c72a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/qml/qml/qqmlengine.h3
-rw-r--r--src/quick/util/qquickimageprovider.h1
-rw-r--r--src/quick/util/qquickpixmapcache.cpp2
3 files changed, 4 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlengine.h b/src/qml/qml/qqmlengine.h
index ec597bc521..0f9e6da63f 100644
--- a/src/qml/qml/qqmlengine.h
+++ b/src/qml/qml/qqmlengine.h
@@ -50,8 +50,9 @@
QT_BEGIN_NAMESPACE
-class Q_QML_EXPORT QQmlImageProviderBase
+class Q_QML_EXPORT QQmlImageProviderBase : public QObject
{
+ Q_OBJECT
public:
enum ImageType : int {
Invalid = 0,
diff --git a/src/quick/util/qquickimageprovider.h b/src/quick/util/qquickimageprovider.h
index f3dba81446..59b1eaf99c 100644
--- a/src/quick/util/qquickimageprovider.h
+++ b/src/quick/util/qquickimageprovider.h
@@ -97,6 +97,7 @@ class QQuickImageProviderOptions;
class Q_QUICK_EXPORT QQuickImageProvider : public QQmlImageProviderBase
{
friend class QQuickImageProviderWithOptions;
+ Q_OBJECT
public:
QQuickImageProvider(ImageType type, Flags flags = Flags());
~QQuickImageProvider() override;
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp
index 69c48280c5..8e56287bba 100644
--- a/src/quick/util/qquickpixmapcache.cpp
+++ b/src/quick/util/qquickpixmapcache.cpp
@@ -1341,7 +1341,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
QQuickImageProvider::ImageType imageType = QQuickImageProvider::Invalid;
QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine);
- QSharedPointer<QQuickImageProvider> provider = enginePrivate->imageProvider(imageProviderId(url)).dynamicCast<QQuickImageProvider>();
+ QSharedPointer<QQuickImageProvider> provider = enginePrivate->imageProvider(imageProviderId(url)).objectCast<QQuickImageProvider>();
// it is safe to use get() as providerV2 does not escape and is outlived by provider
QQuickImageProviderWithOptions *providerV2 = QQuickImageProviderWithOptions::checkedCast(provider.get());
if (provider)