diff options
author | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-06-24 10:31:07 +0200 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-06-30 12:27:04 +0000 |
commit | 52e7aba6bf717c673151c9267040c7a90dbea039 (patch) | |
tree | b9bad5de62d3ddca7c9b2b3987c0af6366f7a17c | |
parent | b0852eb2714eac824bff36216b3301f2e02f82a9 (diff) | |
download | qtbase-52e7aba6bf717c673151c9267040c7a90dbea039.tar.gz |
QFileIconEngine: Remove reference to QFileIconProvider
Keeping the reference may end up in a crash if a created
QIcon outlives the QFileIconProvider and we then try to
generate a pixmap.
The reference is not necessary since the options are queried
only when creating the icon, so they can be saved in the icon
provider.
Task-number: QTBUG-46755
Change-Id: I5c60887c2ed39030a2a20298ff10fd652189e4e7
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
-rw-r--r-- | src/widgets/itemviews/qfileiconprovider.cpp | 11 | ||||
-rw-r--r-- | tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp | 17 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/widgets/itemviews/qfileiconprovider.cpp b/src/widgets/itemviews/qfileiconprovider.cpp index 5bab531290..051cb8e7cc 100644 --- a/src/widgets/itemviews/qfileiconprovider.cpp +++ b/src/widgets/itemviews/qfileiconprovider.cpp @@ -63,8 +63,8 @@ static bool isCacheable(const QFileInfo &fi); class QFileIconEngine : public QPixmapIconEngine { public: - QFileIconEngine(const QFileIconProvider *fip, const QFileInfo &info) - : QPixmapIconEngine(), m_fileIconProvider(fip), m_fileInfo(info) + QFileIconEngine(const QFileInfo &info, QFileIconProvider::Options opts) + : QPixmapIconEngine(), m_fileInfo(info), m_fipOpts(opts) { } QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE @@ -90,7 +90,7 @@ public: } QPlatformTheme::IconOptions iconOptions; - if (m_fileIconProvider->options() & QFileIconProvider::DontUseCustomDirectoryIcons) + if (m_fipOpts & QFileIconProvider::DontUseCustomDirectoryIcons) iconOptions |= QPlatformTheme::DontUseCustomDirectoryIcons; pixmap = theme->fileIconPixmap(m_fileInfo, size, iconOptions); @@ -152,8 +152,8 @@ public: } private: - const QFileIconProvider *m_fileIconProvider; QFileInfo m_fileInfo; + QFileIconProvider::Options m_fipOpts; }; @@ -346,8 +346,7 @@ QIcon QFileIconProviderPrivate::getIcon(const QFileInfo &fi) const if (sizes.isEmpty()) return QIcon(); - Q_Q(const QFileIconProvider); - return QIcon(new QFileIconEngine(q, fi)); + return QIcon(new QFileIconEngine(fi, options)); } /*! diff --git a/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp b/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp index 0bc972d0cb..fba83a24c7 100644 --- a/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp +++ b/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp @@ -58,6 +58,8 @@ private slots: void type_data(); void type(); + + void taskQTBUG_46755_QFileIconEngine_crash(); }; // Subclass that exposes the protected functions. @@ -167,6 +169,21 @@ void tst_QFileIconProvider::type() QVERIFY(!provider.type(info).isEmpty()); } +static QIcon getIcon() +{ + QFileIconProvider fip; + return fip.icon(QDir::currentPath()); +} + +void tst_QFileIconProvider::taskQTBUG_46755_QFileIconEngine_crash() +{ + const QIcon &icon = getIcon(); + foreach (const QSize &size, icon.availableSizes()) + icon.pixmap(size); + + // No crash, all good. +} + QTEST_MAIN(tst_QFileIconProvider) #include "tst_qfileiconprovider.moc" |