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