このページでは

添付プロパティの再利用

この警告カテゴリは、qmllint によって「[attached-property-reuse] 」と表記されます。

親スコープですでに初期化されているアタッチされた型を使用しています

何が起きたのか?

伝播するアタッチド型を複数回初期化しました。

注:これは 主に、QQuickAttachedPropertyPropagator を継承するアタッチド型で発生します。

なぜこれが問題なのか?

伝播型アタッチメントオブジェクトは、インスタンス化されるたびにメモリを消費しますが、初期化は 1 回だけで済みます。

例

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
    }
}

© 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.