aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquickstategroup.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-04-25 10:26:27 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-04-25 11:44:26 +0200
commit3fb46f78cfa4ab753e1d6b066528d5544d37e23d (patch)
tree4fcbf1685bf5dff2bb99f45dc50d71c9d76479bc /src/quick/util/qquickstategroup.cpp
parentd4c8f0b95bec719738aee6ab943914fc62f5aace (diff)
QQuickStateGroup: Check "when" binding for context before evaluating
If it doesn't have a valid context evaluate() will crash. It's unclear how this is triggered, so we cannot easily construct a test. Pick-to: 6.2 6.3 Fixes: QTBUG-102729 Change-Id: I9f08d43bd41e657870fa2f8cf23460570fd9bcee Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/quick/util/qquickstategroup.cpp')
-rw-r--r--src/quick/util/qquickstategroup.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp
index 781d2cf1fb..951afd3e46 100644
--- a/src/quick/util/qquickstategroup.cpp
+++ b/src/quick/util/qquickstategroup.cpp
@@ -380,10 +380,14 @@ bool QQuickStateGroupPrivate::updateAutoState()
const QQmlProperty whenProp(state, u"when"_qs);
const auto potentialWhenBinding = QQmlAnyBinding::ofProperty(whenProp);
Q_ASSERT(!potentialWhenBinding.isUntypedPropertyBinding());
+
// if there is a binding, the value in when might not be up-to-date at this point
- // so we manually reevaluate the binding
- if (auto abstractBinding = dynamic_cast<QQmlBinding *>( potentialWhenBinding.asAbstractBinding()))
- whenValue = abstractBinding->evaluate().toBool();
+ // so we manually re-evaluate the binding
+ if (auto binding = dynamic_cast<QQmlBinding *>(potentialWhenBinding.asAbstractBinding())) {
+ if (binding->hasValidContext())
+ whenValue = binding->evaluate().toBool();
+ }
+
if (whenValue) {
qCDebug(lcStates) << "Setting auto state due to expression";
if (currentState != state->name()) {