參考書籍《Qt quick 核心編程》
書籍作者 https://blog.csdn.net/foruok/article/details/30028711
順便說下 信號也可以連接信號
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.14
Window {
id:root;
visible: true
width: 640
height: 480
title: qsTr("Hello World");
Rectangle {
id:rec;
width:100;
height:100;
anchors.centerIn: parent;
property int num:0;//定義了一個變量num
color: "black";
Text {
id: txt
text: qsTr("text");
color: "white";
anchors.centerIn: parent;
font.pointSize: 24;
}
signal send();
onSend: {
num++;
txt.text = num;
}
Button {
id:btn;
width: 200;
height: 100;
text: "button"
anchors.horizontalCenter: rec.horizontalCenter;
anchors.topMargin: 10;
anchors.top: rec.bottom;
}
Component.onCompleted: {
btn.clicked.connect(send);
}
}
}