qml 一个信号与多个方法关联 和 c++信号与槽类似写法

qml 一个信号与多个方法关联 和 c++信号与槽类似写法

import QtQuick 2.9
import QtQuick.Window 2.2

Window {
    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

posted @ 2018-08-21 09:59  -CQ-  阅读(259)  评论(0编辑  收藏  举报