In questa pagina

Ciclo di alias

Questa categoria di avviso viene indicata da qmllint con il nome " [alias-cycle] ".

La proprietà alias fa parte di un ciclo di alias

Cosa è successo?

Un alias di proprietà risolve a se stesso o a un altro alias che risolve a se stesso.

Di norma, un alias di proprietà dovrebbe fare riferimento a un'altra proprietà, direttamente o indirettamente passando attraverso un'altra proprietà alias.

Se un alias di proprietà fa riferimento, direttamente o indirettamente, a se stesso, forma un ciclo di alias. L’avviso indica che la proprietà alias corrente si trova all’interno di un ciclo di alias o fa riferimento ad esso; si veda l’esempio.

Perché è un problema?

Le istanze dei componenti con cicli di alias non verranno create in fase di esecuzione: risulteranno invece nulle.

Esempio

import QtQuick

Item {
    id: someId
    property alias myself: someId.myself // not ok: referring to itself

    property alias cycle: someId.cycle2 // not ok: indirectly referring to itself
    property alias cycle2: someId.cycle

    property alias indirect: someId.cycle // not ok: referring to alias indirectly referring to itself
}

Per risolvere questo avviso, interrompere i cicli di alias:

import QtQuick

Item {
    id: someId
    Item {
        id: anotherId
        property string myself
        property int cycle
    }
    property alias myself: anotherId.myself // ok: referring to a property

    property alias cycle: someId.cycle2 // ok: does not refer to itself anymore
    property alias cycle2: anotherId.cycle // ok: not a cycle anymore

    property alias indirect: someId.cycle // ok: cycle does not form an alias cycle anymore
}

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