このページでは

宣言の前にVarを使用する

この警告カテゴリーはqmllintによって[var-used-before-declaration]

変数が宣言の前に使われている

何が起こったのでしょうか?

宣言前に変数を使っています。

これはなぜ悪いのでしょうか?

これはコードを読みにくくします。letconst で宣言された変数は、実行時にエラーになります。

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.