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>
This commit is contained in:
J-P Nurmi 2015-10-08 22:27:16 +02:00
parent 5e7d7dfc07
commit 2f90269465
6 changed files with 78 additions and 6 deletions

1
.gitignore vendored
View File

@ -18,6 +18,7 @@
/tests/auto/controls/tst_controls
/tests/auto/sanity/tst_sanity
/tests/auto/snippets/tst_snippets
/tests/auto/theme/tst_theme
/tests/benchmarks/creationtime/tst_creationtime
/tests/benchmarks/objectcount/tst_objectcount

View File

@ -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)

View File

@ -6,4 +6,5 @@ SUBDIRS += \
calendar \
controls \
sanity \
snippets
snippets \
theme

View File

@ -0,0 +1,12 @@
TEMPLATE = app
TARGET = tst_theme
CONFIG += qmltestcase
SOURCES += \
$$PWD/tst_theme.cpp
OTHER_FILES += \
$$PWD/data/*
TESTDATA += \
$$PWD/data/tst_*

View File

@ -0,0 +1,57 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtQuickTest/quicktest.h>
#include <QtGui/qguiapplication.h>
#include <QtQml/qqmlapplicationengine.h>
// based on QUICK_TEST_MAIN() defined in quicktest.h
int main(int argc, char **argv)
{
QTEST_ADD_GPU_BLACKLIST_SUPPORT
QTEST_SET_MAIN_SOURCE_PATH
{
// QTBUG-48651
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.loadData("import Qt.labs.controls 1.0; Slider { } ");
if (engine.rootObjects().isEmpty())
return -1;
}
return quick_test_main(argc, argv, "tst_theme", QUICK_TEST_SOURCE_DIR);
}