附加属性重复使用
此警告类别由 qmllint 拼写为[attached-property-reuse]
。
使用父作用域中已初始化的附加类型
发生了什么?
您多次初始化了一个传播的附加类型。
注意: 这主要发生在从QQuickAttachedPropertyPropagator 继承的附加类型上。
为什么会这样?
传播附加对象每次实例化都会消耗内存,但只需初始化一次。
示例
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 } }
要修复此警告,请查询父类中的附加类型:
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.