aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/types/qqmlbind.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2023-04-14 14:29:19 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2023-04-19 20:01:09 +0200
commit82f2ee8027f733cec5961aac27a171cf0b78a70b (patch)
tree4712029a1290694934c56dab4de031a56767d2c9 /src/qml/types/qqmlbind.cpp
parent3bd201c4da03132354805e220577014e813659ba (diff)
Binding: Reevaluate when before the target changes
...and do not warn about missing properties if when is disabled. Besides avoiding spurious warnings, this also avoids modifying a property only to restore its binding/value directly afterwards. Note that when the binding gets re-enabled, we still trigger the warning. Fixes: QTBUG-112860 Pick-to: 6.5 Change-Id: I5ddd32f2de2dec9da372b08ab4bb5bdb88873e51 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/qml/types/qqmlbind.cpp')
-rw-r--r--src/qml/types/qqmlbind.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/qml/types/qqmlbind.cpp b/src/qml/types/qqmlbind.cpp
index f69462b937..8bfe9d4c4e 100644
--- a/src/qml/types/qqmlbind.cpp
+++ b/src/qml/types/qqmlbind.cpp
@@ -463,10 +463,26 @@ void QQmlBind::setObject(QObject *obj)
eval();
d->when = true;
}
+ /* if "when" and "target" depend on the same property, we might
+ end up here before we could have updated "when". So reevaluate
+ when manually here.
+ */
+ const QQmlProperty whenProp(this, QLatin1StringView("when"));
+ const auto potentialWhenBinding = QQmlAnyBinding::ofProperty(whenProp);
+ if (auto abstractBinding = potentialWhenBinding.asAbstractBinding()) {
+ QQmlBinding *binding = static_cast<QQmlBinding *>(abstractBinding);
+ if (binding->hasValidContext()) {
+ const auto boolType = QMetaType::fromType<bool>();
+ bool when;
+ binding->evaluate(&when, boolType);
+ d->when = when;
+ }
+ }
d->obj = obj;
if (d->componentComplete) {
setTarget(QQmlProperty(d->obj, d->propName, qmlContext(this)));
- d->validate(this);
+ if (d->when)
+ d->validate(this);
}
eval();
}
@@ -520,7 +536,8 @@ void QQmlBind::setProperty(const QString &p)
d->propName = p;
if (d->componentComplete) {
setTarget(QQmlProperty(d->obj, d->propName, qmlContext(this)));
- d->validate(this);
+ if (d->when)
+ d->validate(this);
}
eval();
}