Test.qml
import QtQuick 2.0 Rectangle{ id:forwarder 100 height: 100 color: "#0000FF" signal send() onSend:console.log("xxxx"); MouseArea{ id:mousea anchors.fill: parent onClicked:console.log("1111") } Component.onCompleted:{/**信号处理器**/ mousea.clicked.connect(send) } }
main.qml
import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true 640 height: 480 title: qsTr("Hello World") Test{ onSend:console.log("xxxx"); } }
运行结果:
qml: 1111
qml: xxxx
qml: xxxx