diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 6c5621000e..870f9eb76f 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -438,9 +438,8 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName, if (!theme.isValid()) { theme = QIconTheme(themeName); if (!theme.isValid()) { - qCDebug(lcIconLoader) << "Theme" << themeName << "not found;" - << "trying fallback theme" << fallbackThemeName(); - theme = QIconTheme(fallbackThemeName()); + qCDebug(lcIconLoader) << "Theme" << themeName << "not found"; + return info; } } @@ -582,10 +581,12 @@ QThemeIconInfo QIconLoader::loadIcon(const QString &name) const qCDebug(lcIconLoader) << "Loading icon" << name; QThemeIconInfo iconInfo; - if (!themeName().isEmpty()) { - QStringList visited; - iconInfo = findIconHelper(themeName(), name, visited); - } + QStringList visitedThemes; + if (!themeName().isEmpty()) + iconInfo = findIconHelper(themeName(), name, visitedThemes); + + if (iconInfo.entries.empty() && !fallbackThemeName().isEmpty()) + iconInfo = findIconHelper(fallbackThemeName(), name, visitedThemes); if (iconInfo.entries.empty()) iconInfo = lookupFallbackIcon(name); diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 4ae908058e..0d8213a617 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -732,6 +732,10 @@ void tst_QIcon::fromTheme() // named system icon theme. QIcon::setThemeName(""); // Reset user-theme if (QIcon::themeName().isEmpty()) { + // Test icon from fallback theme even when theme name is empty + QIcon::setFallbackThemeName("fallbacktheme"); + QVERIFY(!QIcon::fromTheme("edit-cut").isNull()); + // Test icon from fallback path even when theme name is empty fallbackIcon = QIcon::fromTheme("red"); QVERIFY(!fallbackIcon.isNull());