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\ingroup qmllint-warnings-and-errors
6
7\title Readonly property
8\brief [read-only-property] A readonly property was written.
9
10\qmllintwarningcategory read-only-property
11
12\section1 Cannot assign to read-only property
13
14\section2 What happened?
15A \l{Read-Only Properties}{read-only property} was written.
16
17\section2 Why is this bad?
18The QML engine will throw a Type Error when it sees the write to a read-only property.
19
20\section2 Example
21\qml
22import QtQuick
23
24Item {
25 id: root
26 readonly property int someNumber: 10
27
28 Component.onCompleted: {
29 someNumber = 20 // not ok: TypeError: Cannot assign to read-only property
30 }
31}
32\endqml
33To fix this warning, remove the write to the read-only property, write to another
34non-read-only property, or remove the readonly modifier if you are the author of
35the property definition.
36\sa{Read-Only Properties}
37*/