- Qt 6.12
- Qt Qml
- QML Lint Warning and Errors
- Stale property read
- Qt 6.12.0 Reference Documentation

# Stale property read

This warning category is spelled `[stale-property-read]` by qmllint.

## Reading non-constant and non-notifiable property

### What happened?

A property that is both non-constant and non-notifyable is used in a binding.

### Why is that bad?

Constant properties never change in value. Notifiable properties notify bindings depending on them when they change in value so the bindings can re-evaluate.

Because this property is neither constant nor notifiable, it could change during the program's execution without notifying dependent bindings. This would leave the bindings in a potentially outdated state, as their value depends on the property.

### Example

     class Circle : public QObject
     {
         Q_OBJECT
         QML_ELEMENT
         Q_PROPERTY(double radius READ radius WRITE setRadius FINAL)
     public:
         double radius() const { return m_radius; }
         void setRadius(double radius) { m_radius = radius; }
     private:
         double m_radius = 1;
     };

     import QtQuick

     Item {
         Circle {
             id: circle
             property double area: Math.PI * radius * radius
         }

         Component.onCompleted: {
             console.log(circle.area) // 3.14159...
             circle.radius = 2
             console.log(circle.area) // 3.14159...
         }
     }

To fix this warning, either mark the property as constant if it will not change in value or make it notifiable.

     class Circle : public QObject
     {
         Q_OBJECT
         QML_ELEMENT
         Q_PROPERTY(double radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
     public:
         double radius() const { return m_radius; }
         void setRadius(double radius) {
             if (radius != m_radius) {
                 m_radius = radius;
                 emit radiusChanged();
             }
         }
     signals:
         void radiusChanged();
     private:
         double m_radius = 1;
     };

     import QtQuick

     Item {
         Circle {
             id: circle
             property double area: Math.PI * radius * radius
         }

         Component.onCompleted: {
             console.log(circle.area) // 3.14159...
             circle.radius = 2
             console.log(circle.area) // 12.5663...
         }
     }