diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-25 15:11:53 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-28 18:51:19 +0100 |
commit | af53fb0e00d694b7cb115b0162ee75d883adff67 (patch) | |
tree | b5e70016e081e32d8215215331db1009a34d9ba7 /src/corelib/kernel/qproperty.cpp | |
parent | 127147feb0428227a5598a6d053501d984a26d51 (diff) |
QProperty: Treat change listener modifying its source property as a loop
This is in line with QML where
import QtQuick 2.15
Rectangle {
width: 100
height: 100
color: "red"
Rectangle {
id: inner
x: 10
y: x
width: 50
height: 50
onYChanged: { console.log("hey"); inner.x = 10}
TapHandler {
onTapped: inner.x = 20
}
}
}
results in a binding loop warning when the tap handler triggers. While
the change handler would only run once, we cannot statically determine
if we need to loop once, twice, or if there actually is a diverging
loop. Thus we unconditionally warn about the binding loop and stop
executing the binding.
As a drive-by, verify in the related test that a change handler which
overwrites its properties binding itself removes the binding.
Change-Id: I5372019c2389ab724c49cd7489ecbd3ebced1c69
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/corelib/kernel/qproperty.cpp')
-rw-r--r-- | src/corelib/kernel/qproperty.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index 5ad0fabd06..fbe582304b 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -100,15 +100,15 @@ void QPropertyBindingPrivate::unlinkAndDeref() void QPropertyBindingPrivate::markDirtyAndNotifyObservers() { - if (dirty) - return; - dirty = true; if (eagerlyUpdating) { error = QPropertyBindingError(QPropertyBindingError::BindingLoop); if (isQQmlPropertyBinding) errorCallBack(this); return; } + if (dirty) + return; + dirty = true; eagerlyUpdating = true; QScopeGuard guard([&](){eagerlyUpdating = false;}); |