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. Pass Qml object in signal
Forum Updated to NodeBB v4.3 + New Features

Pass Qml object in signal

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 630 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    MajidKamali
    wrote on last edited by
    #1

    Hi.
    I created a c++ QObject based class and I use that in qml just fine.
    I want to use object of that type in signal parameter.
    I've done the following:

    // Sender.qml
    signal sigName(var obj) // signal definition
    ...
    CppBasedClass { id: cls } // create object of that type
    ...
    function func() {
       cls.property1 = ... // fill object
    ...
       sigName(cls) // emit signal
    }
    
    // Receiver.qml
    CppBasedClass { id: recv }
    
    Connections {
    ...
       onSigName: {
          recv = obj
          console.log(obj.property1) // works, prints property1 value
          console.log(recv.property1) // <-- does not work, prints nothing
       }
    }
    

    CppBasedClass have many properties and I need autocomplete feature. obj does not have any autocomplete, but recv does.
    How can I achive this?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MajidKamali
      wrote on last edited by
      #2

      Temporarily solved the prblem with this function:

      // equivalent to: obj1 = obj2
          function assign(obj1, obj2) {
              for(var prop in obj2)
                  if(obj2.hasOwnProperty(prop) && typeof obj2[prop] !== 'function')
                      obj1[prop] = obj2[prop]
          }
      

      because obj1 is of type obj2, there is no problem with this approach.

      BUT main question remains unanswered. Why assignment does not work?

      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