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
confusing-pluses.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2025 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-confusing-pluses.html
6
\ingroup qmllint-warnings-and-errors
7
8
\title Confusing pluses
9
\brief [confusing-pluses] Confusing pluses.
10
11
\qmllintwarningcategory confusing-pluses
12
13
\section1 Confusing pluses
14
15
\section2 What happened?
16
JavaScript code uses a combination of operators written with '+' in a confusing
17
way. The neighboring '+' operators may be difficult to distinguish. This can be
18
made worse by unconventional spacing.
19
20
\section2 Why is that bad?
21
It makes the code more difficult to read and may cause confusion.
22
23
\section2 Example
24
\qml
25
import QtQuick
26
27
Item {
28
function f(a: int, b: int) {
29
let x = a++ + b
30
let y = a + +b
31
let z = a + ++b
32
return x + y + z
33
}
34
}
35
\endqml
36
To fix this warning, rewrite the code so that it doesn't contain similar '+'
37
operators next to each other. Simplify expressions where possible. Remove
38
redundant unary operators and spacing, and use parentheses to isolate
39
subexpressions.
40
41
Be mindful that these operators may perform coercions. An expression like
42
\c{a + +b} may not be equivalent to \c{a + b} depending on the type of b.
43
\qml
44
import QtQuick
45
46
Item {
47
function f(a: int, b: int) {
48
let x = (a++) + b
49
let y = a + b
50
let z = a + b + 1
51
return x + y + z
52
}
53
}
54
\endqml
55
*/
qtdeclarative
src
qml
doc
src
qmllint
confusing-pluses.qdoc
Generated on
for Qt by
1.14.0