diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 530f4af8d1..e6951f975e 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -620,11 +620,15 @@ QIconEngine *QIconLoader::iconEngine(const QString &iconName) const qCDebug(lcIconLoader) << "Resolving icon engine for icon" << iconName; auto *platformTheme = QGuiApplicationPrivate::platformTheme(); - auto *iconEngine = hasUserTheme() || !platformTheme ? - new QIconLoaderEngine(iconName) : platformTheme->createIconEngine(iconName); + std::unique_ptr iconEngine; + if (!hasUserTheme() && platformTheme) + iconEngine.reset(platformTheme->createIconEngine(iconName)); + if (!iconEngine || iconEngine->isNull()) { + iconEngine.reset(new QIconLoaderEngine(iconName)); + } - qCDebug(lcIconLoader) << "Resulting engine" << iconEngine; - return iconEngine; + qCDebug(lcIconLoader) << "Resulting engine" << iconEngine.get(); + return iconEngine.release(); } /*! diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 0d8213a617..71df9f12ca 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -552,6 +552,10 @@ void tst_QIcon::availableSizes() void tst_QIcon::name() { + const auto reset = qScopeGuard([]{ + QIcon::setThemeName({}); + QIcon::setThemeSearchPaths({}); + }); { // No name if icon does not come from a theme QIcon icon(":/image.png"); @@ -629,6 +633,7 @@ void tst_QIcon::task184901_badCache() void tst_QIcon::fromTheme() { + const bool abIconFromPlatform = !QIcon::fromTheme("address-book-new").isNull(); QString firstSearchPath = QLatin1String(":/icons"); QString secondSearchPath = QLatin1String(":/second_icons"); QIcon::setThemeSearchPaths(QStringList() << firstSearchPath << secondSearchPath); @@ -725,7 +730,7 @@ void tst_QIcon::fromTheme() // Make sure setting the theme name clears the state QIcon::setThemeName(""); abIcon = QIcon::fromTheme("address-book-new"); - QVERIFY(abIcon.isNull()); + QCOMPARE_NE(abIcon.isNull(), abIconFromPlatform); // Test fallback icon behavior for empty theme names. // Can only reliably test this on systems that don't have a