Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 A readonly property was written.
10
11\section1 Cannot Assign To Read-Only Property
12
13\section2 What happened?
14A \l{Read-Only Properties}{read-only property} was written.
15
16\section2 Why is this bad?
17The QML engine will throw a Type Error when it sees the write to a read-only property.
18
19\section2 Example
20\qml
21import QtQuick
22
23Item {
24 id: root
25 readonly property int someNumber: 10
26
27 Component.onCompleted: {
28 someNumber = 20 // not ok: TypeError: Cannot assign to read-only property
29 }
30}
31\endqml
32You can fix this warning by removing the write to the read-only property, by writing to another
33non-read-only property, or by removing the readonly modifier if the property should no longer be
34considered constant.
35
36\sa{Read-Only Properties}
37*/
38