2 Signals are emitted and pass a QObject to the QML/js code. Both of these signals are interpreted by a single js function doSomething().
This first signal is defined as void mySignalSpecific(Object1 *obj); and is passing as a defined class.
The second is defined as void mySignalQObject(QObject *obj); and is passing as a QObject.
Both of these produce different results inside the function doSomething();
void mySignalSpecific(Object1 *obj) outputs:
QVariant(Object1*)
undefined
here we do not have access to myObject1.getObject2(); Also I did not see anywhere in the docs of how I could cast a QVariant in QML/js to be able to access it correctly.
void mySignalQObject(QObject *obj) outputs:
Object1(name = "")
object1 name property
and all works as intended. Right here you can see that the class is being casted differently when it is the same object. This method forces qcasting inside the c++ code or a separate function.
The third output when using view.rootContext()->setContextProperty("myObject1",object1); to give access to the object outputs.
Object2(0x69fc60)
Now the third example is not signal based but still shows how the same object is being casted differently when it should not be.
Bookmarks