diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-03-01 16:00:20 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-03-07 11:20:57 +0100 |
commit | bad5a7ac1fe3ec39c6c9a0111f1514177a69315e (patch) | |
tree | fb9616ce2140faaf48bceeced111ab85eb687683 /src/qml | |
parent | a997b376c79fb955c4c2344eae7da5fec4853958 (diff) |
Fail gracefully when binding an attached property where the object is null
Overlay.overlay is an attached property that holds the window overlay
item, our documentation promises that it can be attached to anything,
but will be null if the thing is not in a window.
When using QQuickView on a QML code that declares an item which
tries to bind something to the Overlay.overlay property, then the overlay
will be null, and creating it will fail because there is also no window
yet. This crashes further down processing when trying to create the
binding.
While this cannot be made to work (modifying the window is not possible
in QML that doesn't declare a Window and is instead loaded into a
QQuickView), it should also not crash.
Add a nullptr check where it did crash, add a test that reproduces the
crash, and with the fix merely spits out a warning.
Fixes: QTBUG-122894
Pick-to: 6.7 6.6 6.5
Change-Id: Ie4438657a6855b44409edb28431e04eb9875a392
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Kwanghyo Park <kwanghyo.park@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/qml/qqmlanybinding_p.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlanybinding_p.h b/src/qml/qml/qqmlanybinding_p.h index fbe4c12350..66d2fc573d 100644 --- a/src/qml/qml/qqmlanybinding_p.h +++ b/src/qml/qml/qqmlanybinding_p.h @@ -73,10 +73,10 @@ public: { QQmlAnyBinding binding; Q_ASSERT(object); - QQmlData *data = QQmlData::get(object, true); auto coreIndex = index.coreIndex(); // we don't support bindable properties on value types so far - if (!index.hasValueTypeIndex() && data->propertyCache->property(coreIndex)->isBindable()) { + if (!index.hasValueTypeIndex() + && QQmlData::ensurePropertyCache(object)->property(coreIndex)->isBindable()) { auto metaProp = object->metaObject()->property(coreIndex); QUntypedBindable bindable = metaProp.bindable(object); binding = bindable.binding(); |