This warning category is spelled [var-used-before-declaration] by qmllint.
You used a variable before you declared it.
This makes the code harder to read. Variables declared with let or const will error out at runtime.
import QtQuick
Item {
function f() {
x = 42; // x is used before its declaration
let x;
}
Component.onCompleted: f()
}To fix this warning, move the declaration before the usage:
import QtQuick
Item {
function f() {
let x;
x = 42;
}
Component.onCompleted: f()
}See also JavaScript Expressions in QML Documents.
© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-6.9/qmllint-warnings-and-errors-var-used-before-declaration.html