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
stale-property-read.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2026 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 Stale property read
8
\brief [stale-property-read] Reading non-constant and non-notifiable property.
9
10
\qmllintwarningcategory stale-property-read
11
12
\section1 Reading non-constant and non-notifiable property
13
14
\section2 What happened?
15
A property that is both non-constant and non-notifyable is used in a binding.
16
17
\section2 Why is that bad?
18
\l{The Property System}{Constant properties} never change in value.
19
\l{The Property System}{Notifiable properties} notify bindings depending on
20
them when they change in value so the bindings can re-evaluate.
21
22
Because this property is neither constant nor notifiable, it could change
23
during the program's execution without notifying dependent bindings. This
24
would leave the bindings in a potentially outdated state, as their value
25
depends on the property.
26
27
\section2 Example
28
\code
29
class Circle : public QObject
30
{
31
Q_OBJECT
32
QML_ELEMENT
33
Q_PROPERTY(double radius READ radius WRITE setRadius FINAL)
34
public:
35
double radius() const { return m_radius; }
36
void setRadius(double radius) { m_radius = radius; }
37
private:
38
double m_radius = 1;
39
};
40
\endcode
41
\qml
42
import QtQuick
43
44
Item {
45
Circle {
46
id: circle
47
property double area: Math.PI * radius * radius
48
}
49
50
Component.onCompleted: {
51
console.log(circle.area) // 3.14159...
52
circle.radius = 2
53
console.log(circle.area) // 3.14159...
54
}
55
}
56
\endqml
57
To fix this warning, either mark the property as
58
\l{The Property System}{constant} if it will not change in value or make it
59
\l{The Property System}{notifiable}.
60
\code
61
class Circle : public QObject
62
{
63
Q_OBJECT
64
QML_ELEMENT
65
Q_PROPERTY(double radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
66
public:
67
double radius() const { return m_radius; }
68
void setRadius(double radius) {
69
if (radius != m_radius) {
70
m_radius = radius;
71
emit radiusChanged();
72
}
73
}
74
signals:
75
void radiusChanged();
76
private:
77
double m_radius = 1;
78
};
79
\endcode
80
\qml
81
import QtQuick
82
83
Item {
84
Circle {
85
id: circle
86
property double area: Math.PI * radius * radius
87
}
88
89
Component.onCompleted: {
90
console.log(circle.area) // 3.14159...
91
circle.radius = 2
92
console.log(circle.area) // 12.5663...
93
}
94
}
95
\endqml
96
*/
qtdeclarative
src
qml
doc
src
qmllint
stale-property-read.qdoc
Generated on
for Qt by
1.16.1