1、屬性別名使用注意點
正常使用:
Rectangle{ property alias buttonText: textItem.text width: 100; height: 30; color: "yellow" Text{ id: textItem } }
注意點一:屬性別名在整個組件初始化完畢之后才可以使用
id: root property alias buttonText: textItem.text //下面的代碼會報錯,因為代碼執行到這里,buttonText還是一個未定義的值
property alias buttonText2: root.buttonText Component.onCompleted: buttonText = "some text"
注意點二:屬性別名可以與現有屬性同名,但會覆蓋現有屬性
Rectangle{ id: coloredrectangle property alias color: bluerectangle.color color: "red" Rectangle{ id: bluerectangle color: '#1234ff' } }