From 6147b56c03a89bf8f3bfd88fc4838718e06ecb48 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 27 Aug 2020 15:15:21 +0200 Subject: Fix crash when importing a style without first importing Controls The following code import QtQuick import QtQuick.Controls.Material ApplicationWindow { width: 200 height: 200 visible: true } produced an error in Qt 5: QQmlApplicationEngine failed to load component qrc:/main.qml:4 ApplicationWindow is not a type In Qt 6, the types are provided by the qmldir, so the import will work, but as QtQuickControls2Plugin has not been loaded, there is no QQuickTheme object yet, and so the style will not work as expected (any colors, fonts, etc. from the theme will not be used by the style). Produce a warning for this scenario, and test each style to make sure that we don't crash. Fixes: QTBUG-86280 Change-Id: I99f940255f56da0522ad192ae5da4c9110ea308e Reviewed-by: Fabian Kosmale --- src/imports/controls/default/qtquickcontrols2defaultstyleplugin.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/imports/controls/default') diff --git a/src/imports/controls/default/qtquickcontrols2defaultstyleplugin.cpp b/src/imports/controls/default/qtquickcontrols2defaultstyleplugin.cpp index a486658e..6b4b3bc3 100644 --- a/src/imports/controls/default/qtquickcontrols2defaultstyleplugin.cpp +++ b/src/imports/controls/default/qtquickcontrols2defaultstyleplugin.cpp @@ -70,6 +70,9 @@ void QtQuickControls2DefaultStylePlugin::registerTypes(const char *uri) { QQuickStylePlugin::registerTypes(uri); + if (!QQuickTheme::instance()) + return; + theme.initialize(QQuickTheme::instance()); } -- cgit v1.2.3