Scenario:
I have a Qt app which runs on Qt 5.9.4 commercial edition. Its a QtQuick
and QML
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 of someItem
in a C++ method or a lambda without changing anything in the QML. Basically hook up to the onClick signal signal of someItem
from C++ side itself. How can I do it?