本文介绍了如何在 QML 中捕获信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将 s 信号从一个 qml 组件发送到另一个?
How I can send s signal from one qml component to another?
下面是一个例子:
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?
推荐答案
你应该使用组件信号的connect()
方法(信号本身就是对象).
You should use connect()
method of component's signals (signals themselves are objects).
function clickHandler() {
console.log('main clicked')
}
Component.onCompleted: {
main.clicked.connect(clickHandler)
}
参见 http://developer.qt.nokia.com/doc/qt-4.8/qmlevents.html
这篇关于如何在 QML 中捕获信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!