From 1ceb8efeef7cf2f32ab069e0939a96e26ba1a9f6 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 19 Feb 2018 15:52:44 +0100 Subject: Reset QQuickStyle when the QtQuick.Controls 2 plugin is unloaded Cleanup global static data in QQuickStyle when the controls plugin is unloaded (qmlClearTypeRegistrations()). This ensures that the style is resolved as appropriate when the controls plugin is reloaded. Change-Id: Icebb835e057e6063e4fc0ca035c6836560bc7c14 Reviewed-by: Mitch Curtis --- tests/auto/qquickstyle/tst_qquickstyle.cpp | 36 ++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qquickstyle/tst_qquickstyle.cpp b/tests/auto/qquickstyle/tst_qquickstyle.cpp index 1ce2a034..9de947a6 100644 --- a/tests/auto/qquickstyle/tst_qquickstyle.cpp +++ b/tests/auto/qquickstyle/tst_qquickstyle.cpp @@ -46,21 +46,41 @@ class tst_QQuickStyle : public QObject Q_OBJECT private slots: - void init(); + void cleanup(); void lookup(); void commandLineArgument(); void environmentVariables(); void availableStyles(); + +private: + void loadControls(); + void unloadControls(); }; -void tst_QQuickStyle::init() +void tst_QQuickStyle::cleanup() { - QQuickStylePrivate::reset(); + unloadControls(); + QGuiApplicationPrivate::styleOverride.clear(); qunsetenv("QT_QUICK_CONTROLS_STYLE"); qunsetenv("QT_QUICK_CONTROLS_FALLBACK_STYLE"); } +void tst_QQuickStyle::loadControls() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import QtQuick 2.0; import QtQuick.Controls 2.1; Control { }", QUrl()); + + QScopedPointer object(component.create()); + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); +} + +void tst_QQuickStyle::unloadControls() +{ + qmlClearTypeRegistrations(); +} + void tst_QQuickStyle::lookup() { QVERIFY(QQuickStyle::name().isEmpty()); @@ -70,12 +90,7 @@ void tst_QQuickStyle::lookup() QCOMPARE(QQuickStyle::name(), QString("Material")); QVERIFY(!QQuickStyle::path().isEmpty()); - QQmlEngine engine; - QQmlComponent component(&engine); - component.setData("import QtQuick 2.0; import QtQuick.Controls 2.1; Control { }", QUrl()); - - QScopedPointer object(component.create()); - QVERIFY(!object.isNull()); + loadControls(); QCOMPARE(QQuickStyle::name(), QString("Material")); QVERIFY(!QQuickStyle::path().isEmpty()); @@ -84,6 +99,9 @@ void tst_QQuickStyle::lookup() void tst_QQuickStyle::commandLineArgument() { QGuiApplicationPrivate::styleOverride = "CmdLineArgStyle"; + + loadControls(); + QCOMPARE(QQuickStyle::name(), QString("CmdLineArgStyle")); } -- cgit v1.2.3