Search code examples
qtqmlqt-quick

Does QML support access specifiers like Private for properties?


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.


Solution

  • 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.