Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does QML support access specifiers like Private for properties?

Tags:

qt

qt-quick

qml

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.

like image 333
DNamto Avatar asked Nov 06 '12 13:11

DNamto


People also ask

How to define property in QML?

A property is an attribute of an object that can be assigned a static value or bound to a dynamic expression. A property's value can be read by other objects. Generally it can also be modified by another object, unless a particular QML type has explicitly disallowed this for a specific property.

What is property in Qt?

The property type can be any type supported by QVariant, or it can be a user-defined type. In this example, class QDate is considered to be a user-defined type. Q_PROPERTY(QDate date READ getDate WRITE setDate) Because QDate is user-defined, you must include the <QDate> header file with the property declaration.

What is QObject in QML?

The QtObject type is a non-visual element which contains only the objectName property. It can also be useful for C++ integration, as it is just a plain QObject.

How do I change the properties of QML in C++?

You should always use QObject::setProperty(), QQmlProperty or QMetaProperty::write() to change a QML property value, to ensure the QML engine is made aware of the property change.


1 Answers

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.

like image 128
Pavel Osipov Avatar answered Oct 12 '22 10:10

Pavel Osipov