From 49b3865f99343d3b91392b2560e217f6f48438ea Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 30 Jul 2012 18:01:01 +1000 Subject: Document readonly property syntax Reviewed-by: Chris Adams Change-Id: Ibaf68b39526824098aa67f7d1fdce6d12e3b3111 Reviewed-by: Chris Adams --- src/qml/doc/src/syntax/objectattributes.qdoc | 29 +++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/qml/doc') diff --git a/src/qml/doc/src/syntax/objectattributes.qdoc b/src/qml/doc/src/syntax/objectattributes.qdoc index f199b6abba..741b7cbb91 100644 --- a/src/qml/doc/src/syntax/objectattributes.qdoc +++ b/src/qml/doc/src/syntax/objectattributes.qdoc @@ -515,7 +515,7 @@ aliasing an aliasing property will also result in an error. \snippet qml/properties.qml alias complete -When importing a \l{QML Object Types}QML object type} with a property alias in +When importing a \l{QML Object Types}{QML object type} with a property alias in the root object, however, the property appear as a regular Qt property and consequently can be used in alias references. @@ -587,6 +587,33 @@ default property to automatically reassign children of the TabWidget as children of an inner ListView. +\section3 Read-Only Properties + +An object declaration may define a read-only property using the \c readonly +keyword, with the following syntax: + +\code + readonly property : +\endcode + +Read-only properties must be assigned a value on initialization. After a +read-only property is initialized, it no longer possible to give it a value, +whether from imperative code or otherwise. + +For example, the code in the \c Component.onCompleted block below is invalid: + +\qml +Item { + readonly property int someNumber: 10 + + Component.onCompleted: someNumber = 20 // doesn't work, causes an error +} +\endqml + +\note A read-only property cannot also be a \l{Default Properties}{default} or +\l {Property Aliases}{alias} property. + + \section2 Signal Attributes A signal is a notification from an object that some event has occurred: for -- cgit v1.2.3