How do i send a signal with parameters from QML to cpp code
-
Hi,
I would appreciate some hints to this problem that I'm facing. I am creating dynamic components and would like to send some data back to the cpp code.
(this is just pseudo code)
in main.qml :@Rectangle {
id: containerMyComponent { id: mycomp }
}
@
in "MyComponent.qml"@Item {
id: myitemvar component = Qt.createComponent("Wheel.qml"); //dynamic objects... var object = component.createObject(myitem);
}@
finally "Wheel.qml"
@ Rectangle {
id:myWheel
Component.onCompleted: {
//SEND SOME DATA (x,y) TO CPP CODE
}
}@potential cpp code:
@view->setSource(QUrl("qrc:/QML/main.qml"));
QGraphicsObject *object = view->rootObject();
??@I am not sure how the how to send data as a signal from wheel component to cpp code. Any ideas?
-
"Using QML Bindings in C++ Applications":http://doc.trolltech.com/4.7-snapshot/qtbinding.html#calling-functions
-
Thanks!
Actually, it was this document that helped:
For dynamic objects use the connect call...
So in "Wheel.qml"
@Rectangle {
id:myWheel
Component.onCompleted: {
//SEND SOME DATA (x,y) TO CPP CODE
mySignal(x,y)
}
}@in “MyComponent.qml”
@
//the syntax is interesting here..you simply connect the signals but don't specify the arguments..
object.mySignal.connect(myitem.anothersignal); @finally in cpp:
@QGraphicsObject *object = view->rootObject();
QObject::connect(object,SIGNAL(anothersignal(int,int)),this, SLOT(executeKClosure(int,int)));
@ -
no cpp detected..., only JS
-
I've updated my reply...the js code is crucial to propagate the data to the cpp code.