From aea585d9ffcb8a5a8664831de01cbfac018262ad Mon Sep 17 00:00:00 2001 From: Sami Shalayel Date: Fri, 13 Oct 2023 14:20:02 +0200 Subject: doc: add read-only-property warning in qmllint warnings Add description of the warning and an example on how to fix it. Task-number: QTBUG-111137 Change-Id: I7ec0f77ac21d8fb6146a38f43977de0ef604af7c Reviewed-by: Ulf Hermann --- src/qml/doc/src/qmllint/read-only-property.qdoc | 28 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/qml/doc') diff --git a/src/qml/doc/src/qmllint/read-only-property.qdoc b/src/qml/doc/src/qmllint/read-only-property.qdoc index 8a6a266b6e..7bc6b5fcc2 100644 --- a/src/qml/doc/src/qmllint/read-only-property.qdoc +++ b/src/qml/doc/src/qmllint/read-only-property.qdoc @@ -5,22 +5,34 @@ \page qmllint-warnings-and-errors-read-only-property.html \ingroup qmllint-warnings-and-errors -\title read-only-property -\brief BRIEF +\title Readonly Property +\brief A readonly property was written. -\section1 read-only-property +\section1 Cannot Assign To Read-Only Property \section2 What happened? -TODO +A \l{Read-Only Properties}{read-only property} was written. \section2 Why is this bad? -TODO +The QML engine will throw a Type Error when it sees the write to a read-only property. \section2 Example \qml +import QtQuick + +Item { + id: root + readonly property int someNumber: 10 + + Component.onCompleted: { + someNumber = 20 // not ok: TypeError: Cannot assign to read-only property + } +} \endqml -You can fix this warning by TODO -\qml -\endqml +You can fix this warning by removing the write to the read-only property, by writing to another +non-read-only property, or by removing the readonly modifier if the property should no longer be +considered constant. + +\sa{Read-Only Properties} */ -- cgit v1.2.3