Qt 6.11 is out! See what's new in the release
blog
How can I send a signal to an Item which is inside a Loader ?
QML and Qt Quick
2
Posts
2
Posters
1.8k
Views
1
Watching
-
How can I send a signal to an Item which is inside a Loader ?
-
Hi,
AFAIK, you can do it in following ways:
- Using "Connect()":http://doc.qt.io/qt-5/qtqml-syntax-signals.html#connecting-signals-to-methods-and-signals
- Using "Connections()":http://doc.qt.io/qt-5/qml-qtqml-connections.html
An example :
@
Item {
id: item
width: 100
height: 150signal sendMessage(string msg) Loader { id: loader width: 100 height: 100 sourceComponent: comp Component.onCompleted: item.sendMessage.connect(loader.item.setText) //comment Component.onCompleted if using Connections and vice versa }// Connections {
// target: item
// onSendMessage: {
// loader.item.setText(msg)
// }
// }Component { id: comp Rectangle { anchors.fill: parent color: "red" function setText(msg) { mytext.text = msg } Text { id: mytext anchors.centerIn: parent } } } Button { text: "Click Me" y: 110 onClicked: item.sendMessage("Hello Qt") }}
@