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
function-used-before-declaration.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2026 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-function-used-before-declaration.html
6
\ingroup qmllint-warnings-and-errors
7
8
\title Function used before its declaration
9
\brief [function-used-before-declaration] A function was used before its declaration.
10
11
\qmllintwarningcategory function-used-before-declaration
12
13
This category is disabled by default.
14
15
\section1 Function usage before its declaration
16
17
\section2 What happened?
18
You called a function or used its name before the function was declared.
19
20
\section2 Why is that bad?
21
It makes the code more difficult to read and may cause confusion.
22
23
Note that the function is made available before its declaration due to
24
\l{https://developer.mozilla.org/en-US/docs/Glossary/Hoisting}{hoisting}.
25
26
\section2 Example
27
\qml
28
import QtQuick
29
30
Item {
31
function f() {
32
g(42)
33
function g() { return 42; }
34
}
35
}
36
\endqml
37
38
To fix this warning, move the declaration before the usage.
39
40
\qml
41
import QtQuick
42
43
Item {
44
function f() {
45
function g() { return 42; }
46
g(42)
47
}
48
}
49
\endqml
50
*/
qtdeclarative
src
qml
doc
src
qmllint
function-used-before-declaration.qdoc
Generated on
for Qt by
1.16.1