[Qt-qml] How catch C++ signal in qml
bea.lam at nokia.com
bea.lam at nokia.com
Wed Aug 18 07:38:39 CEST 2010
Hi Patryk,
>
> When I'm trying catch this signal - tick in MyPlayer file, I get something like: Couldn't find slot/function: myAction. But when I put myAction in main.qml everything works fine. For now, I add to main.qml:
>
> function myAction(data)
> {
> player.myAction(data);
> }
>
> but, I think this is bad solution when I want to catch signal from c++ in a child. So, Is it posible to catch signal from c++ directly in MyPlayer.qml ? Without this function myAction in main.qml ?
Yes, you need to connect to the child object, rather than the view->rootObject(), when you call QObject::connect(). To make it easier to locate the child object, you can give it an object name:
Rectangle {
id: page
MyPlayer {
id: player
objectName: "player"
}
}
And then use QObject::findChild() to locate it and connect to its signal:
QObject *obj = view->rootObject();
QObject *player = obj->findChild<QObject *>("player");
connect(mediaObject, SIGNAL(tick(qint64)), player, SLOT(myAction(qint64)));
regards,
Bea
More information about the Qt-qml
mailing list