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