Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.0.0 Beta2
-
None
Description
I think that onValueChanged() should only be called one time in the following code.
#include <QProperty> int main(int argc, char *argv[]) { QProperty<int> x; QProperty<int> y; QProperty<int> z(10); QProperty<QString> str; int xCount = 0; x.setBinding([&]() { xCount++; return y.value() * 10; }); int yCount = 0; y.setBinding([&]() { yCount++; return z.value() * 5; }); int strCount = 0; str.setBinding([&](){ strCount++; return QString("x:%1 y:%2 z:%3").arg(x.value()).arg(y.value()).arg(z.value()); }); int valueChangeCount = 0; auto valueChangedHandle = str.onValueChanged([&valueChangeCount, &str](){ valueChangeCount++; qDebug() << "Called:" << str.value(); }); z.setValue(13); //Change valueChangeCount should only be 1, instead of 3? qDebug() << "Str:" << valueChangeCount << str.value() << valueChangeCount; }
Instead the change handler gets call 3 times because:
x depends on y
y depends on z
str depends on x, y, z
When updating z, it cause y binding to execute, then x binding, which I guess is 3 changes, but since this cascade happen from a single set from z, it might be more efficient if onValueChanged() is only executed once.