In questa pagina

Errori di profondità di ricorsione

Questa categoria di avviso viene indicata da qmllint con il nome " [recursion-depth-errors] ".

Superata la profondità massima dell'istruzione o dell'espressione

Cosa è successo?

Un'istruzione o un'espressione QML era annidata a un livello troppo profondo per il compilatore. Questo di solito accade solo nel codice generato, dove le istruzioni o le espressioni possono essere molto lunghe, poiché il limite di ricorsione è solitamente sufficientemente ampio per qualsiasi documento QML ragionevole.

Perché è un problema?

Il motore QML non sarà in grado di eseguire questo codice.

Esempio

import QtQuick

Item {
    function f() {
        let x = 1 + 1 + .... + 1 // maximum depth exceeded: add too many ones together
        return x
    }

    Item { Item { .... } } // maximum depth exceeded: too many nested Item's
}

Per risolvere questo avviso, generare automaticamente frammenti di codice più piccoli. Suddividere i componenti profondamente annidati in più file o componenti inline, oppure suddividere le espressioni profondamente annidate in più espressioni:

import QtQuick

Item {
    function f() {
        let x = 1 + 1 + .... + 1 // first half of the split
        x += 1 + 1 + .... + 1 // second half of the split
        return x
    }

    component NestedItem : Item { Item {... }} // first half of the nested Item
    component DeeplyNestedItem: Item { ... NestedItem{} ... } // second half of the nested Items + NestedItem
    DeeplyNestedItem {}
}

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