Connecting QML signals with Qt slots.
-
Hi! I have such code:
@Item {
signal itemClicked()MouseArea {
anchor.fill: parent
onClicked: itemClicked()
}
}@Can I connect itemClicked() to slot in cpp application?
@QDeclarativeEngine *engine = new QDeclarativeEngine;
QDeclarativeComponent component(engine, QUrl::fromLocalFile("qml/TestQML/TestQML.qml"));
QObject *myObject = component.create();
QDeclarativeItem item = qobject_cast<QDeclarativeItem>(myObject);
qDebug()<<QObject::connect(item, SIGNAL(titleBarClicked()), &viewer, SLOT(showMaximized()));@connect() retuns true, but it doesn't work.
-
-
In the example the connect has titleBarClicked and the QML has itemClicked, is that just a typo? (if so, I don't see obviously wrong -- it looks like it should be working)
-
bq. In the example the connect has titleBarClicked and the QML has itemClicked, is that just a typo?
Yes, it's a typo. But it doesn't work :(
bq. see if this helps
I need reverse connection..
-
Hi,
Could you add a bug report on "http://bugreports.qt.nokia.com":bugreports.qt.nokia.com with a small example to reproduce the problem?
Thanks,
Michael -
I've tried this feature in a simple project and it works. So the mistake somewhere in the my test app.
P.S. You can see this "code example":http://www.fileconvoy.com/filelist.php?id=gfd6e298a19c42fa5359453643e0534cdae6ef.
Maybe you are know what's wrong :)