From 60061f679c500f89ef46f33be9f5d2f0cfb8a63d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 26 May 2024 11:14:07 +0200 Subject: [PATCH] QIcon: don't load image twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QIcon::addPixmap() creates an icon engine when not yet available. During the initialization, the filename of the image is already passed to the icon engine and some (e.g. svg icon engine) already loads it. Afterwards the image is loaded again with addFile(). Avoid this by checking if the ctor of the icon engine already loaded the file and don't call addFile() afterwards in this case. Fixes: QTBUG-8151 Change-Id: I9289f17e5d703c08a82ce51ce8bded70feb6f82d Reviewed-by: Morten Johan Sørvig Reviewed-by: Volker Hilsheimer --- src/gui/image/qicon.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 8dc36bdc2c1..07e646efa5a 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -1100,6 +1100,7 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State if (fileName.isEmpty()) return; detach(); + bool alreadyAdded = false; if (!d) { QFileInfo info(fileName); @@ -1109,10 +1110,12 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State suffix = QMimeDatabase().mimeTypeForFile(info).preferredSuffix(); // determination from contents #endif // mimetype QIconEngine *engine = iconEngineFromSuffix(fileName, suffix); + if (engine) + alreadyAdded = !engine->isNull(); d = new QIconPrivate(engine ? engine : new QPixmapIconEngine); } - - d->engine->addFile(fileName, size, mode, state); + if (!alreadyAdded) + d->engine->addFile(fileName, size, mode, state); // Check if a "@Nx" file exists and add it. QString atNxFileName = qt_findAtNxFile(fileName, qApp->devicePixelRatio());