[Interest] QML bindings and redundant property changes

Daniel França daniel.franca at gmail.com
Wed Apr 1 22:57:57 CEST 2015


For me even your second example calls onPerimeterChanged only once.
It seems that Qt is smart enough to only notify once when it's evalating an
expression (that's actually a js function).


Em qua, 1 de abr de 2015 às 19:12, Preet <prismatic.project at gmail.com>
escreveu:

> Hi all
>
> I want to understand how redundant QML property binding evaluations are
> mitigated. Does anyone have a high level idea of how this might be done?
>
> Consider the following case of properties describing a triangle:
>
> Item {
>    property real a: 2;
>    property real b: 3;
>    property real c: Math.sqrt(a*a + b*b);
>    property real perimeter: a+b+c;
>
>    onPerimeterChanged: { console.log("perimeter changed"); }
> }
>
> If you update either 'a' or 'b', onPerimeterChanged will only be called
> once. But if you think about the dependencies between the properties, the
> perimeter depends on a, b and c:
>
> change a -> change perimeter
> change a -> change c -> change perimeter
>
> I would have expected two invocations of onPerimeterChanged, but it gets
> called only once. The QML engine avoids the redundant change and I'm
> curious as to how this is done.
>
> If you add enough dependencies though, you'll start getting multiple
> updates:
>
> Item {
>    property real a: 2;
>    property real b: 3;
>    property real c: Math.sqrt(a*a + b*b);
>    property real alt0: a+1;
>    property real alt1: alt0+1;
>    property real perimeter: a+b+c+alt1;
>
>    onPerimeterChanged: { console.log("perimeter changed"); }
> }
>
> This will result in onPerimeterChanged being called twice.
>
>
> Preet
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150401/ad6710e7/attachment.html>


More information about the Interest mailing list