Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
recursion-depth-errors.qdoc
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qmllint-warnings-and-errors-recursion-depth-errors.html
6\ingroup qmllint-warnings-and-errors
7
8\title Recursion depths errors
9\brief [recursion-depth-errors] Qml statement or expression is too deeply nested.
10
11\qmllintwarningcategory recursion-depth-errors
12
13\section1 Maximum statement or expression depth exceeded
14\section2 What happened?
15A QML statement or expression was too deeply nested for the compiler. This usually only happens for
16generated code where statements or expressions can be very long, as the recursion limit is usually
17large enough for any sensible QML document.
18
19\section2 Why is this bad?
20The QML engine will not be able to run this code.
21
22\section2 Example
23\qml
24import QtQuick
25
26Item {
27 function f() {
28 let x = 1 + 1 + .... + 1 // maximum depth exceeded: add too many ones together
29 return x
30 }
31
32 Item { Item { .... } } // maximum depth exceeded: too many nested Item's
33}
34\endqml
35
36To fix this warning, auto-generate smaller code pieces. Split deeply nested
37Components in multiple files or inline components, or split deeply nested
38expressions into multiple expressions:
39\qml
40import QtQuick
41
42Item {
43 function f() {
44 let x = 1 + 1 + .... + 1 // first half of the split
45 x += 1 + 1 + .... + 1 // second half of the split
46 return x
47 }
48
49 component NestedItem : Item { Item {... }} // first half of the nested Item
50 component DeeplyNestedItem: Item { ... NestedItem{} ... } // second half of the nested Items + NestedItem
51 DeeplyNestedItem {}
52}
53\endqml
54*/