A limitation of automatic property updates

QML does its best to determine when the function value may change, but it is not omnipotent. For our last function, it can easily determine that the function result depends on the value of the textField.text property, so it will re-evaluate the binding if that value changes. However, in some cases, it can't know that a function may return a different value the next time it is called, and in such situations, the statement will not be re-evaluated. Consider the following property binding:

Label {    function colorByTime() {        var d = new Date();        var seconds = d.getSeconds();        if(seconds < 15) return "red";        if(seconds < 30) return "green";        if(seconds < 45) return "blue";        return "purple";    } color: colorByTime() ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.