Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. handover 'property references' to JavaScript?
QtWS25 Last Chance

handover 'property references' to JavaScript?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 527 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Frime
    wrote on last edited by
    #1

    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!
    Frime

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xargs1
      wrote on last edited by
      #2

      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
              callback(test);
              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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved