En esta página

Se ha utilizado «var» antes de la declaración

qmllint denomina esta categoría de advertencia « [var-used-before-declaration] ».

Aquí se utiliza una variable antes de su declaración

¿Qué ha pasado?

Has utilizado una variable antes de declararla.

¿Por qué es un error?

Esto dificulta la lectura del código. Las variables declaradas con « let » o « const » darán error en tiempo de ejecución.

Ejemplo

import QtQuick

Item {
    function f() {
        x = 42; // x is used before its declaration
        let x;
    }

    Component.onCompleted: f()
}

Para solucionar esta advertencia, coloca la declaración antes de su uso:

import QtQuick

Item {
    function f() {
        let x;
        x = 42;
    }

    Component.onCompleted: f()
}

Véase también «Expresiones JavaScript en documentos 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.