aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/qmllint/read-only-property.qdoc
blob: 7bc6b5fcc2a5f49ee0e6cb29147095a3b870f69a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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}
*/