How I can send s signal from one qml component to another?
Below is an example:
Rectangle {
id: main
width: 360; height: 360
signal clicked()
Text {
id: testStr
anchors.centerIn: parent
text: "Hello World"
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: { Qt.quit(); }
}
Component.onCompleted: clicked()
onClicked: testStr.text = "Demo"
}
How do I capture the signal in other Component?
QML
add_pq.qml
You should use
connect()
method of component's signals (signals themselves are objects).See http://developer.qt.nokia.com/doc/qt-4.8/qmlevents.html
In the other object, you simply add a
on
word followed by the signal name. EG:(clicked is somewhat a confusing signal name because it's common. But if you had called your signal
orange
, you'd make the bindingonOrange:
)you can use QML connection element