Does QML support access specifiers like Private for properties?

余生颓废 提交于 2019-12-03 07:01:26

问题


I just want to know do we have any concept access specifiers like private property in QML as we have in C++.

If not if would like to know in case i have about 10 properties in my QML component but i have to limit the access to only 2 properties. how can we achieve this scenario.


回答1:


There is no such builtin feature in QML itself, but here is Qt Quick Components approach:

Item {
  property int sum: internal.a + internal.b
  QtObject {
    id: internal
    property int a: 1
    property int b: 2
  }
}

Properties of 'internal' object are invisible outside of Item, but may be freely used inside of it.



来源:https://stackoverflow.com/questions/13252158/does-qml-support-access-specifiers-like-private-for-properties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!