[Solved]Create a read only property in qml
-
//Whatever.qml
@
Rectangle{property string modelType: object.stringModel
//.......
}
@What I want to do is, inside the Whatever.qml the modelType could be read or altered
but for other's components modelType is a read only propertyCurrently I am using function and QObject to hide the property
Do pure qml have other choices for us?Thanks -
In Qt Quick 2, you can actually declare readonly property like this:
@readonly property string modelType: object.stringModel@
In this case you would not be able to modify it after creation. If you need to modify it inside Whatever.qml you could instead create an internal property and declare a public readonly alias to it. -
Thanks for your helps