[Interest] QML bindings and redundant property changes

Preet prismatic.project at gmail.com
Wed Apr 1 19:11:57 CEST 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150401/f62a9878/attachment.html>


More information about the Interest mailing list