首页 > 其他 > 详细

Qt-qml alias别名注意点

时间:2019-11-13 17:18:58      阅读:152      评论:0      收藏:0      [点我收藏+]

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

Qt-qml alias别名注意点

原文:https://www.cnblogs.com/fancyop/p/Qt_qml_notice.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!