qml 属性 property

//main.qml

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    property double version: 1.2

    Text {
        id: m_txt
        width: 100
        height: 100
        text: qsTr("text" + " " + version)
    }
}

//main.qml

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    property double version: 1.2

    Text {
        id: m_txt
        width: 100
        height: 100
        text: qsTr("text" + " " + version)
    }

//最后执行的代码段在omponent.onCompleted执行
    Component.onCompleted: {
        version = 2.3
    }
}

猜你喜欢

转载自blog.csdn.net/yongwoozzang/article/details/111054155