Variabile utilizzata prima della dichiarazione
Questa categoria di avviso viene indicata da qmllint come " [var-used-before-declaration] ".
Qui la variabile viene utilizzata prima della sua dichiarazione
Cosa è successo?
Hai utilizzato una variabile prima di averla dichiarata.
Perché è un problema?
Questo rende il codice più difficile da leggere. Le variabili dichiarate con let o const genereranno un errore in fase di esecuzione.
Esempio
import QtQuick
Item {
function f() {
x = 42; // x is used before its declaration
let x;
}
Component.onCompleted: f()
}Per risolvere questo avviso, sposta la dichiarazione prima dell'utilizzo:
import QtQuick
Item {
function f() {
let x;
x = 42;
}
Component.onCompleted: f()
}Vedi anche Espressioni JavaScript nei documenti QML.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.