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' } }