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 <volker.hilsheimer@qt.io>
Change-Id: I6dc8cf435815b92da270d74fe992843336af23e2
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 9e7c5670509ac81efdf78b691e70e5ce3d408a09)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Lu YaNing 2022-06-30 11:01:54 +08:00 committed by Qt Cherry-pick Bot
parent cebcabc5af
commit 95fdc63a99

View File

@ -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();