qml 一个信号与多个方法关联 和 c++信号与槽类似写法
import QtQuick 2.9import QtQuick.Window 2.2Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Rectangle{ id:relay signal messageReceived(string person,string notice) Component.onCompleted: { relay.messageReceived.connect(sendToPost) relay.messageReceived.connect(sendToTelegraph) relay.messageReceived.connect(sendToEmail) relay.messageReceived("xxx","yyy") } function sendToPost(person,notice){ console.log("send to post"+person +","+notice) } function sendToTelegraph(person,notice){ console.log("send to legraph"+person +","+notice) } function sendToEmail(person,notice){ console.log("send to email"+person +","+notice) } }}
结果:
qml: send to postxxx,yyy
qml: send to legraphxxx,yyy
qml: send to emailxxx,yyy