Wiederverwendung der angehängten Eigenschaft
Diese Warnkategorie wird von qmllint [attached-property-reuse]
geschrieben.
Verwendung eines angehängten Typs, der bereits in einem übergeordneten Bereich initialisiert wurde
Was ist passiert?
Sie haben einen propagierenden angehängten Typ mehrfach initialisiert.
Hinweis: Dies geschieht meist bei angehängten Typen, die von QQuickAttachedPropertyPropagator erben.
Warum ist das schlecht?
Propagierende angehängte Objekte verbrauchen bei jeder Instanzierung Speicher, müssen aber nur einmal initialisiert werden.
Beispiel
import QtQuick import QtQuick.Templates as T import QtQuick.Controls.Material // contains the Material attached type T.ToolBar { id: control // first instantiation of Material's attached property property color c: Material.toolBarColor background: Rectangle { // second instantiation of Material's attached property, wrong! color: Material.toolBarColor } }
Um diese Warnung zu beheben, fragen Sie den angehängten Typ vom Elternteil ab:
import QtQuick import QtQuick.Templates as T import QtQuick.Controls.Material // contains the Material attached type T.ToolBar { id: control // first instantiation of Material's attached property property color c: Material.toolBarColor background: Rectangle { // use control's attached property, correct! color: control.Material.toolBarColor } }
© 2025 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.