このページでは

宣言前に使用された関数

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

このカテゴリはデフォルトでは無効になっています。

宣言前の関数の使用

何が起こりましたか?

関数が宣言される前に関数を呼び出したり、関数の名前を使ったりしました。

なぜそれが悪いのですか?

コードが読みにくくなり、混乱を招く可能性があります。

関数が宣言前に使用可能になるのは、hoistingのためであることに注意してください。

import QtQuick

Item {
    function f() {
        g(42)
        function g() { return 42; }
    }
}

この警告を修正するには、宣言を使用法の前に移動します。

import QtQuick

Item {
    function f() {
        function g() { return 42; }
        g(42)
    }
}

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