diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2020-08-27 15:15:21 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2020-08-27 20:16:30 +0200 |
commit | 6147b56c03a89bf8f3bfd88fc4838718e06ecb48 (patch) | |
tree | 3a47383d28b8626db044143642c05df21b4944cb /src/imports/controls/material | |
parent | 7f29e89c26ae2babc358b1c4e6f965af6ec759f4 (diff) |
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'src/imports/controls/material')
-rw-r--r-- | src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp index 6066d3f5..47e7e877 100644 --- a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp +++ b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp @@ -71,6 +71,9 @@ void QtQuickControls2MaterialStylePlugin::registerTypes(const char *uri) { QQuickStylePlugin::registerTypes(uri); + if (!QQuickTheme::instance()) + return; + QQuickMaterialStyle::initGlobals(); theme.initialize(QQuickTheme::instance()); } |