Réutilisation des propriétés associées
Cette catégorie d'avertissement est orthographiée « [attached-property-reuse] » par qmllint.
Utilisation d’un type associé déjà initialisé dans une portée parente
Que s'est-il passé ?
Vous avez initialisé plusieurs fois un type attaché se propageant.
Remarque : cela se produit principalement avec les types attachés qui héritent de ` QQuickAttachedPropertyPropagator`.
Pourquoi est-ce un problème ?
Les objets attachés propagés consomment de la mémoire à chaque instanciation, alors qu'ils ne doivent être initialisés qu'une seule fois.
Exemple
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
}
}Pour corriger cet avertissement, interrogez le type attaché à partir du parent :
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
}
}© 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.