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