[Development] QML: grouping property changes for a single callback invocation

Alberto Mardegan mardy at users.sourceforge.net
Sat Mar 3 18:15:40 CET 2012


Hi all,
  sorry for the intricated subject, I couldn't find a concise and
understandable way to express what I mean. :-)

Often it happens to me that I want to run some code when two or more
properties change on a QML object. A real life example is the contentX
and contentY properties from Flickable.

Now, I don't care which one of these properties change: suppose that I
just want to do this:

=======
onContentXChanged: updatePos()
onContentYChanged: updatePos()

function updatePos() {
    myObject.setPos(Qt.Point(contentX, contentY))
}
=======

Now, the code above has a couple of issues:

1) Performance: if both contentX and contentY change, updatePos() will
be called twice, unnecessarily.

2) Jagginess (and correctness): when the flickable contents move from
(0, 0) to (1, 1), myObject will first have its position set to (0, 1),
which is not correct.


So, question time:
1) Am I missing something, or does the situation stand as I described it?
2) Can we do something about it for Qt5? :-)

Would it be reasonable to make it so that the following syntax caused
the property changes trigger the updatePos() callback in a queued
connection, only once:

onContentXChanged:
onContentYChanged: updatePos()

Or, even better, if we get the "on" keyword to work in this case as
Thiago suggested, we could write:

on contentX, contentY: updatePos()


Would that make sense, and be possible for Qt 5?

Ciao,
  Alberto

-- 
http://blog.mardy.it <- geek in un lingua international!



More information about the Development mailing list