Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Bindings bug or feature

$
0
0
Hi, One important feature of a declarative language is that you don’t know in which order the declarations will be applied in, or the order the side-effects (signal handlers, binding expressions) will be evaluated in. In practice, there is an order defined by the engine implementation, but it is best not to rely on that, as it is an implementation detail rather than a well-specified behaviour (ie, API contract). To ensure that an imperative expression is evaluated after a binding evaluation occurs, you can trigger the imperative function via a Timer started as a side-effect of the binding expression. Example: property bool triggerUpdate: false property var someProperty: {     var newValue = Math.random();     if (triggerUpdate) {         timer.start();           }     return newValue; } Timer {     id: timer     interval: 0 // will trigger upon returning to the Qt Event Loop     onTriggered: {         updateViews() // or whatever     } } Component.onCompleted: triggerUpdate = true; // will trigger re-evaluation of someProperty binding, and anything bound to someProperty In the preceding case, the updateViews() function is guaranteed to be called after ALL binding expressions involving someProperty have been re-evaluated, since the Timer’s onTriggered handler will be invoked at some point in the future via the Qt Event Loop. I hope this helps! Cheers, Chris Adams. http://www.qinetic.com.au – The Qt And QML Experts

Viewing all articles
Browse latest Browse all 4972

Trending Articles