本页内容

递归深度错误

qmllint 将此警告类别拼写为“[recursion-depth-errors] ”。

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

发生了什么?

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

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