古いプロパティを読む
この警告カテゴリーはqmllintによって[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; };
© 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.