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
var-used-before-declaration.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
\ingroup qmllint-warnings-and-errors
6
7
\title Var used before declaration
8
\brief [var-used-before-declaration] A JavaScript variable was used before its declaration.
9
10
\qmllintwarningcategory var-used-before-declaration
11
12
\section1 Variable is used here before its declaration
13
14
\section2 What happened?
15
You used a variable before you declared it.
16
17
\sa {JavaScript Expressions in QML Documents}
18
19
\section2 Why is this bad?
20
This makes the code harder to read. Variables declared with
21
\c let or \c const will error out at runtime.
22
23
\section2 Example
24
\qml
25
import QtQuick
26
27
Item {
28
function f() {
29
x = 42; // x is used before its declaration
30
let x;
31
}
32
33
Component.onCompleted: f()
34
}
35
\endqml
36
To fix this warning, move the declaration before the usage:
37
\qml
38
import QtQuick
39
40
Item {
41
function f() {
42
let x;
43
x = 42;
44
}
45
46
Component.onCompleted: f()
47
}
48
\endqml
49
*/
qtdeclarative
src
qml
doc
src
qmllint
var-used-before-declaration.qdoc
Generated on
for Qt by
1.16.1