Sur cette page

Var utilisé avant la déclaration

Cette catégorie d'avertissement a été orthographiée [var-used-before-declaration] par qmllint.

Une variable est utilisée ici avant sa déclaration

Qu'est-ce qui s'est passé ?

Vous avez utilisé une variable avant de l'avoir déclarée.

Pourquoi est-ce mauvais ?

Cela rend le code plus difficile à lire. Les variables déclarées avec let ou const seront rejetées à l'exécution.

Exemple

import QtQuick

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

    Component.onCompleted: f()
}

Pour corriger cet avertissement, placez la déclaration avant l'utilisation :

import QtQuick

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

    Component.onCompleted: f()
}

Voir aussi les expressions JavaScript dans les documents 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.