Veraltete Eigenschaft lesen
Diese Warnkategorie wird von qmllint [stale-property-read] geschrieben.
Lesen einer nicht-konstanten und nicht-notifizierbaren Eigenschaft
Was ist passiert?
Eine Eigenschaft, die sowohl nicht konstant als auch nicht benachrichtigungsfähig ist, wird in einem Datenfluss verwendet.
Warum ist das schlecht?
Konstante Eigenschaften ändern nie ihren Wert. Meldepflichtige Eigenschaften benachrichtigen Bindungen, die von ihnen abhängig sind, wenn sich ihr Wert ändert, so dass die Bindungen eine Neubewertung vornehmen können.
Da diese Eigenschaft weder konstant noch anzeigepflichtig ist, könnte sie sich während der Programmausführung ändern, ohne dass abhängige Bindungen benachrichtigt werden. Dies würde die Bindungen in einem potentiell veralteten Zustand lassen, da ihr Wert von der Eigenschaft abhängt.
Beispiel
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... } }
Um diese Warnung zu beheben, markieren Sie die Eigenschaft entweder als konstant, wenn sich ihr Wert nicht ändern wird, oder machen Sie sie anzeigepflichtig.
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.