From 9e7c5670509ac81efdf78b691e70e5ce3d408a09 Mon Sep 17 00:00:00 2001 From: Lu YaNing Date: Thu, 30 Jun 2022 11:01:54 +0800 Subject: QIcon: remove icon from cache if the cached engine fails to load An icon that is not null by the time it is inserted in the cache can become null, depending on the QIconEngine implementation. For example, when an application with a shortcut exists on the desktop, uninstall the application, and then install the application again, the acquisition of the application icon will fail. The reason is that after installing the application for the second time, the qtIconCache will not be updated when the icon is acquired. Done-with: Volker Hilsheimer Pick-to: 5.15 6.2 6.3 6.4 Change-Id: I6dc8cf435815b92da270d74fe992843336af23e2 Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer --- src/gui/image/qicon.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 38e66b1dc0..08c4667c6c 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -1276,11 +1276,15 @@ void QIcon::setFallbackThemeName(const QString &name) */ QIcon QIcon::fromTheme(const QString &name) { - QIcon icon; - if (qtIconCache()->contains(name)) { - icon = *qtIconCache()->object(name); - } else if (QDir::isAbsolutePath(name)) { + if (QIcon *cachedIcon = qtIconCache()->object(name)) { + if (!cachedIcon->isNull()) + return *cachedIcon; + qtIconCache()->remove(name); + } + + QIcon icon; + if (QDir::isAbsolutePath(name)) { return QIcon(name); } else { QPlatformTheme * const platformTheme = QGuiApplicationPrivate::platformTheme(); -- cgit v1.2.3