Nesta página

Var usado antes da declaração

Essa categoria de aviso é denominada “ [var-used-before-declaration] ” pelo qmllint.

A variável é usada aqui antes de sua declaração

O que aconteceu?

Você usou uma variável antes de declará-la.

Por que isso é ruim?

Isso torna o código mais difícil de ler. Variáveis declaradas com let ou const gerarão erros em tempo de execução.

Exemplo

import QtQuick

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

    Component.onCompleted: f()
}

Para corrigir esse aviso, mova a declaração para antes do uso:

import QtQuick

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

    Component.onCompleted: f()
}

Veja também Expressões JavaScript em 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.