[Qt-qml] How catch C++ signal in qml
Patryk Górniak
patryk.lukasz.gorniak at gmail.com
Mon Aug 16 19:46:18 CEST 2010
Hi,
I was wondering, how can I catch C++ signal in child object in qml? For
example,
I have something like this ( this is only draft:) )
void MyClass::MyClass()
{
mediaObject = new Phonon::MediaObject();
QDeclarativeView* view = new QDeclarativeView();
view->setSource(QUrl::fromLocalFile("main.qml"));
Object* obj = (QObject*) view->rootObject();
connect(mediaObject,
SIGNAL(tick(qint64)),
obj,
SLOT(myAction(qint64))
);
}
and my *main.qml:*
import Qt 4.7
Rectangle {
id: page
MyPlayer{
id: player
}
}
*
MyPlayer file:*
Rectangle {
function myAction(data)
{
console.log(data);
}
}
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 ?
Thanks,
Patryk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100816/b307b477/attachment.html
More information about the Qt-qml
mailing list