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