QML内部的信号与槽函数
//goodmao.qml
import QtQuick 2.12
import QtQuick.Controls 2.14
Rectangle {
width: 200
height: 100
signal testSignal(var aValue) //定义信号
Button {
anchorts.fill: parent
text: qsTr("cilck")
onClick: {
testSignal(9527) //发射信号
}
}
function testFunction (aValue) { //槽函数
console.log("aValue: " + aValue)
}
Component.onCompleted: { //建立连接:连接信号与槽函数
testSignal.connect(testFunction)
}
}

本文介绍了一个QML示例,展示了如何定义和使用信号与槽函数。通过一个具体的例子,详细说明了信号的发射及如何将信号与槽函数进行连接。

被折叠的 条评论
为什么被折叠?



