付属プロパティの再利用

この警告カテゴリーは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.