In questa pagina

Riutilizzo delle proprietà associate

Questa categoria di avviso viene indicata da qmllint come " [attached-property-reuse] ".

Utilizzo di un tipo associato già inizializzato in un ambito padre

Cosa è successo?

Hai inizializzato più volte un tipo associato propagante.

Nota: ciò accade principalmente per i tipi collegati che ereditano da ` QQuickAttachedPropertyPropagator`.

Perché è un problema?

Gli oggetti allegati propaganti consumano memoria ad ogni istanziazione, ma devono essere inizializzati una sola volta.

Esempio

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

Per risolvere questo avviso, interrogare il tipo associato dal genitore:

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.