就是在具体的实例对象中写function方法,然后调用
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Column{
//实例对象
Button{
id:btn
text:'btn Z'
//
onTextChanged: {
console.log(text)
}
//槽函数
onClicked:{
// console.log(text)
text = add(mul(1,2),20)
}
//自定义方法
function add(num1,num2){
return num1+num2
}
function mul(num1,num2){
return num1*num2
}
}
Label{
text:btn.text
color:'red'
font.pointSize: 11
}
}
// MainForm {
// anchors.fill: parent
// mouseArea.onClicked: {
// console.log(qsTr('Clicked on background. Text: "' + textEdit.text + '"'))
// }
// }
}