QIcon: don't load image twice
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 <morten.sorvig@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
6843e5d26d
commit
60061f679c
@ -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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user