aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/qmllint/recursion-depth-errors.qdoc
blob: ed0d2c09b2368e7befb2aede094b9b65f7f6d656 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
\page qmllint-warnings-and-errors-recursion-depth-errors.html
\ingroup qmllint-warnings-and-errors

\title Recursion Depths Errors
\brief Qml statement or expression is too deeply nested.

\section1 Maximum Statement Or Expression Depth Exceeded
\section2 What happened?
A QML statement or expression was too deeply nested for the compiler. This usually only happens for
generated code where statements or expressions can be very long, as the recursion limit is usually
large enough for any sensible QML document.

\section2 Why is this bad?
The QML engine will not be able to run this code.

\section2 Example
\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
}
\endqml

You can fix this warning by auto-generating smaller code pieces. You could split deeply nested
Components in multiple files or inline components, or split deeply nested expressions into multiple
expressions:
\qml
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 {}
}
\endqml
*/