Qt-qml alias别名注意点


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM