Unsolved How to hook up to the onClick event of a QML item from C++ side using the QQuickItem pointer to the QML item
-
Scenario:
I have a Qt app which runs on Qt 5.9.4 commercial edition. Its aQtQuick
andQML
based application which is running on iOS and Android.I have a
QML
item on the UI like this:SomeItem { text: qsTr("Some Item") objectName: "someitem" visible: false onClicked: { console.log("Some item was clicked") } }
I have a C++ function which can easily control the properties of
SomeItem
.void MyCppClass::Func() { QQuickItem *someItem = qml_engine->rootObjects()[0]->findChild<QQuickItem*>("someitem"); someItem->setVisible(true); // this works // How to listen to someItem's onClick event here }
Question:
I want to listen to the onClick event ofsomeItem
in a C++ method or a lambda without changing anything in the QML. Basically hook up to the onClick signal signal ofsomeItem
from C++ side itself. How can I do it?