このページでは

宣言前に `var` を使用

この警告カテゴリは、qmllint によって「[var-used-before-declaration] 」と表記されます。

ここで変数が宣言される前に使用されています

何が起きたのか?

変数を宣言する前に使用してしまいました。

なぜ問題なのでしょうか?

これにより、コードの可読性が低下します。let やconst で宣言された変数は、実行時にエラーとなります。

例

import QtQuick

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

    Component.onCompleted: f()
}

この警告を解消するには、宣言を使用箇所よりも前に移動します:

import QtQuick

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

    Component.onCompleted: f()
}

「QMLドキュメントにおけるJavaScript式」も参照してください 。

© 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.