이 페이지에서

오래된 속성 읽기

이 경고 카테고리의 철자는 [stale-property-read] 입니다.

비상수 및 통지할 수 없는 속성 읽기

무슨 일이 일어났나요?

상수가 아니면서 통지할 수 없는 프로퍼티가 바인딩에 사용되었습니다.

이것이 왜 나쁜가요?

상수프로퍼티는 값이 절대 변하지 않습니다. 통지 가능 속성은 값이 변경되면 그에 따라 바인딩에 통지하여 바인딩이 재평가할 수 있도록 합니다.

이 프로퍼티는 상수도 아니고 통지 가능하지도 않기 때문에 종속 바인딩에 알리지 않고 프로그램 실행 중에 변경될 수 있습니다. 이렇게 되면 바인딩의 값이 프로퍼티에 따라 달라지므로 바인딩이 잠재적으로 오래된 상태가 될 수 있습니다.

예시

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...
    }
}

이 경고를 해결하려면 값이 변경되지 않을 경우 속성을 상수로 표시하거나 알림 가능으로 설정하세요.

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...
    }
}

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.