handover 'property references' to JavaScript?

  • Hi together,

    does anybody has an idea how to get something like this working?

    property int test;
    onTestChanged: console.log("Awesome!!!")
    // pseudo callback caller 
    Component.onCompleted: callbackHandler(test); 
    function callbackHandler(prop)
      prop = 42;
     // now I expect "Aawesome" output.

    Is there a way to handover property references to java script functions?

    I would like to register a callback to a third party JavaScript library running in QML JS Engine. I know, that this isn't the qtest way to get things running, but in this case it's kind of ... let's call "Case Study" ^^

    Thank you very much in advance!

  • If you pass an object, rather than an int, it's a reference:

        property var test: ({ value: 1 })
        Component.onCompleted: {
            console.log(test.value);    // prints 1
            console.log(test.value);   // prints 42
        function callback(prop) {
            prop.value = 42;

    Unfortunately, no "changed" signal is emitted by "var" properties, so you can't have an onChanged handler.

Log in to reply