Question about order of execution by property change.



  • my code is like below.

    ClassA.qml

    @
    Rectangle {
    ClassB { id:b }
    MouseArea {
    onClicked: {
    b.propX = false;
    doSomething(); // A
    }
    }
    }
    @

    ClassB.qml

    @
    Rectangle {
    property bool propX: true
    onPropXChanged: doAnything(); // B
    Rectangle {
    visible: propX
    onVisibleChanged: doWhatever(); // C
    }
    }
    @

    if I click the mousearea of ClassA, what's the order of excution of the A~C?



  • For me it would be C to A,

    b.propX turns to false so it triggers doWhatever() which is topmost Item then triggers doAnything() and finally doSomething since it comes after b.propX = false.

    To make sure you could have your functions as followed :

    @function doSomething()
    {
    console.log( "doSomething" )
    }

    function doAnything()
    {
    console.log( "doAnything" )
    }

    function doWhatever()
    {
    console.log( "doWhatever" )
    }@

    This way you can actually see what is the order and if it is always the same


  • Moderators

    I don't know the internal workings of the engine enough to answer with confidence. My opinion is you should not depend on the order being the same: those things are processed by meta object calls, it might happen - for example - that the order is different on another machine, or on a different operating system.

    There was a splendid series of blogs about QML engine on KDAB's blog. "A very interesting read":http://www.kdab.com/qml-engine-internals-part-1-qml-file-loading/.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.