summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qiconloader.cpp
diff options
context:
space:
mode:
authorJens Bache-Wiig <jbache@trolltech.com>2010-03-04 10:16:16 (GMT)
committerJens Bache-Wiig <jbache@trolltech.com>2010-03-04 10:19:16 (GMT)
commit7727a4355876607a1a022ff54e2570dae883f79c (patch)
treec88526dd233bc33136b17d49f8af60946649f2a3 /src/gui/image/qiconloader.cpp
parent6f974452ec60ec03fd64bb2d12be6544435ae6be (diff)
downloadQt-7727a4355876607a1a022ff54e2570dae883f79c.zip
Qt-7727a4355876607a1a022ff54e2570dae883f79c.tar.gz
Qt-7727a4355876607a1a022ff54e2570dae883f79c.tar.bz2
Do not crash when loading themed icons statically
We do not officially support static loading of icons. In fact they still crash for simple png cases due to missing X11 resources. But since we lazily create themed icons we can certainly avoid the crash in this case. You will not be able to use fallbacks here though, since we cannot know if a fallback should be used or not in this case. Reviewed-by: ogoffart Task-number: QTBUG-8666
Diffstat (limited to 'src/gui/image/qiconloader.cpp')
-rw-r--r--src/gui/image/qiconloader.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index b35e80a..72ec2e8 100644
--- a/src/gui/image/qiconloader.cpp
+++ b/src/gui/image/qiconloader.cpp
@@ -85,19 +85,30 @@ static QString fallbackTheme()
}
QIconLoader::QIconLoader() :
- m_themeKey(1), m_supportsSvg(false)
+ m_themeKey(1), m_supportsSvg(false), m_initialized(false)
{
- m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName();
- if (m_systemTheme.isEmpty())
- m_systemTheme = fallbackTheme();
+}
+
+// We lazily initialize the loader to make static icons
+// work. Though we do not officially support this.
+void QIconLoader::ensureInitialized()
+{
+ if (!m_initialized) {
+ m_initialized = true;
+
+ Q_ASSERT(qApp);
+ m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName();
+ if (m_systemTheme.isEmpty())
+ m_systemTheme = fallbackTheme();
#ifndef QT_NO_LIBRARY
- QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid,
- QLatin1String("/iconengines"),
- Qt::CaseInsensitive);
- if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
- m_supportsSvg = true;
+ QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid,
+ QLatin1String("/iconengines"),
+ Qt::CaseInsensitive);
+ if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
+ m_supportsSvg = true;
#endif //QT_NO_LIBRARY
+ }
}
QIconLoader *QIconLoader::instance()
@@ -339,6 +350,9 @@ bool QIconLoaderEngine::hasIcon() const
// Lazily load the icon
void QIconLoaderEngine::ensureLoaded()
{
+
+ iconLoaderInstance()->ensureInitialized();
+
if (!(iconLoaderInstance()->themeKey() == m_key)) {
while (!m_entries.isEmpty())