diff options
Diffstat (limited to 'src/qml/doc/src/qmllint/read-only-property.qdoc')
-rw-r--r-- | src/qml/doc/src/qmllint/read-only-property.qdoc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/qml/doc/src/qmllint/read-only-property.qdoc b/src/qml/doc/src/qmllint/read-only-property.qdoc new file mode 100644 index 0000000000..7bc6b5fcc2 --- /dev/null +++ b/src/qml/doc/src/qmllint/read-only-property.qdoc @@ -0,0 +1,38 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! +\page qmllint-warnings-and-errors-read-only-property.html +\ingroup qmllint-warnings-and-errors + +\title Readonly Property +\brief A readonly property was written. + +\section1 Cannot Assign To Read-Only Property + +\section2 What happened? +A \l{Read-Only Properties}{read-only property} was written. + +\section2 Why is this bad? +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 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} +*/ + |