递归深度错误
此警告类别由 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 {} }
© 2025 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.