Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
read-only-property.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qmllint-warnings-and-errors-read-only-property.html
6
\ingroup qmllint-warnings-and-errors
7
8
\title Readonly property
9
\brief [read-only-property] A readonly property was written.
10
11
\qmllintwarningcategory read-only-property
12
13
\section1 Cannot assign to read-only property
14
15
\section2 What happened?
16
A \l{Read-Only Properties}{read-only property} was written.
17
18
\section2 Why is this bad?
19
The QML engine will throw a Type Error when it sees the write to a read-only property.
20
21
\section2 Example
22
\qml
23
import QtQuick
24
25
Item {
26
id: root
27
readonly property int someNumber: 10
28
29
Component.onCompleted: {
30
someNumber = 20 // not ok: TypeError: Cannot assign to read-only property
31
}
32
}
33
\endqml
34
To fix this warning, remove the write to the read-only property, write to another
35
non-read-only property, or remove the readonly modifier if you are the author of
36
the property definition.
37
\sa{Read-Only Properties}
38
*/
qtdeclarative
src
qml
doc
src
qmllint
read-only-property.qdoc
Generated on
for Qt by
1.14.0