aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/controls/qquicktheme.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-10-08 22:27:16 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-10-09 13:18:52 +0000
commit2f902694656d67d671d9a8616060d598a478e7b7 (patch)
treee0cf7e891247d736ebd6737c2d6d9db96c2949cd /src/imports/controls/qquicktheme.cpp
parent5e7d7dfc07ea00b53873a6ad5399f2400781f8b9 (diff)
Fix crash in theme code when loading engines in succession
Store global engine specific themes as dynamic properties on the engines themselves. This avoids the problem that storing engines and their themes to a hash map had that destroyed engines and themes were not cleaned up from the hash map. Change-Id: I7330995339c263d456f74d33f6535d5ac7d9d5d4 Task-number: QTBUG-48651 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com> Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Diffstat (limited to 'src/imports/controls/qquicktheme.cpp')
-rw-r--r--src/imports/controls/qquicktheme.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/imports/controls/qquicktheme.cpp b/src/imports/controls/qquicktheme.cpp
index 395d60d7..7fec28c9 100644
--- a/src/imports/controls/qquicktheme.cpp
+++ b/src/imports/controls/qquicktheme.cpp
@@ -102,11 +102,12 @@ Q_GLOBAL_STATIC_WITH_ARGS(QQuickThemeData, globalThemeData, (QString::fromLatin1
static QQuickThemeAttached *themeInstance(QQmlEngine *engine)
{
- static QHash<QQmlEngine *, QQuickThemeAttached *> themes;
- QHash<QQmlEngine *, QQuickThemeAttached *>::iterator it = themes.find(engine);
- if (it == themes.end())
- it = themes.insert(engine, new QQuickThemeAttached(*globalThemeData(), engine));
- return it.value();
+ QQuickThemeAttached *theme = engine->property("_q_quicktheme").value<QQuickThemeAttached *>();
+ if (!theme) {
+ theme = new QQuickThemeAttached(*globalThemeData(), engine);
+ engine->setProperty("_q_quicktheme", QVariant::fromValue(theme));
+ }
+ return theme;
}
static QQuickThemeAttached *attachedTheme(QObject *object)