宣言の前に使用された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式も参照してください

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