diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 36f499711e9..91da21c477d 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -1238,6 +1238,9 @@ QString QIcon::fallbackThemeName() themeSearchPath() containing an index.theme file describing its contents. + \note This should be done before creating \l QGuiApplication, to ensure + correct initialization. + \sa fallbackThemeName(), themeSearchPaths(), themeName() */ void QIcon::setFallbackThemeName(const QString &name) diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 15ab1b3cd90..3fa3bb9c598 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -112,10 +112,9 @@ extern QFactoryLoader *qt_iconEngineFactoryLoader(); // qicon.cpp void QIconLoader::ensureInitialized() { if (!m_initialized) { + if (!QGuiApplicationPrivate::platformTheme()) + return; // it's too early: try again later (QTBUG-74252) m_initialized = true; - - Q_ASSERT(qApp); - m_systemTheme = systemThemeName(); if (m_systemTheme.isEmpty()) @@ -125,6 +124,16 @@ void QIconLoader::ensureInitialized() } } +/*! + \internal + Gets an instance. + + \l QIcon::setFallbackThemeName() should be called before QGuiApplication is + created, to avoid a race condition (QTBUG-74252). When this function is + called from there, ensureInitialized() does not succeed because there + is no QPlatformTheme yet, so systemThemeName() is empty, and we don't want + m_systemTheme to get intialized to the fallback theme instead of the normal one. +*/ QIconLoader *QIconLoader::instance() { iconLoaderInstance()->ensureInitialized();