Pass Qml object in signal
Unsolved
QML and Qt Quick
-
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? -
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?