QtQuick(QML)自學之路(5)自定義信號

參考書籍《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);
        }
    }
}

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章