summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoni Poikelin <joni.poikelin@qt.io>2018-12-13 09:01:34 +0200
committerJoni Poikelin <joni.poikelin@qt.io>2019-01-28 14:52:57 +0000
commit9bbeb7e6e8fb0fdd743b741dce61543fc4246ee2 (patch)
tree91a5588994b100a550a66fef71300614b91aec5f
parent3b514f853595c686d4ed8830567c1f27ea533faf (diff)
Prevent QPixmap::load from touching QPixmapCache in non-gui threads
Change-Id: Ied0fec48c81298743f694f317dd60e58d356f69a Fixes: QTBUG-72523 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r--src/gui/image/qpixmap.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index 4b2334ae52..ea6697cc39 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -714,8 +714,8 @@ QBitmap QPixmap::createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode)
control the conversion.
Note that QPixmaps are automatically added to the QPixmapCache
- when loaded from a file; the key used is internal and can not
- be acquired.
+ when loaded from a file in main thread; the key used is internal
+ and cannot be acquired.
\sa loadFromData(), {QPixmap#Reading and Writing Image
Files}{Reading and Writing Image Files}
@@ -729,6 +729,7 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
// Note: If no extension is provided, we try to match the
// file against known plugin extensions
if (info.completeSuffix().isEmpty() || info.exists()) {
+ const bool inGuiThread = qApp->thread() == QThread::currentThread();
QString key = QLatin1String("qt_pixmap")
% info.absoluteFilePath()
@@ -736,13 +737,14 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
% HexString<quint64>(info.size())
% HexString<uint>(data ? data->pixelType() : QPlatformPixmap::PixmapType);
- if (QPixmapCache::find(key, this))
+ if (inGuiThread && QPixmapCache::find(key, this))
return true;
data = QPlatformPixmap::create(0, 0, data ? data->pixelType() : QPlatformPixmap::PixmapType);
if (data->fromFile(fileName, format, flags)) {
- QPixmapCache::insert(key, *this);
+ if (inGuiThread)
+ QPixmapCache::insert(key, *this);
return true;
}
}