递归深度错误

语句或表达式最大深度超过

发生了什么?

一个 QML 语句或表达式嵌套得太深,超出了编译器的处理能力。这通常只发生在生成的代码中,其中语句或表达式可能非常长,因为递归限制通常足够大,可以处理任何有意义的 QML 文档。

为什么这很糟糕?

QML 引擎将无法运行此代码。

例子

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
}

您可以通过自动生成更小的代码片段来修复此警告。您可以将嵌套过深的组件拆分为多个文件或在行内组件中拆分,或将嵌套过深的表达式拆分为多个表达式。

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

© 2024 Qt 公司有限公司。其中包含的文档贡献的版权归其各自的所有者。本提供的文档根据自由软件基金会的出版,遵守 GNU 自由文档许可证版本 1.3 的条款。Qt 以及相应的徽标是芬兰 Qt 公司及/或在其他国家的商标。所有其他商标均为其各自所有者的财产。