在本页中

在声明之前使用的函数

该警告类别由 qmllint 拼写[function-used-before-declaration]

该类别默认为禁用。

函数在声明前使用

发生了什么?

您在函数声明之前调用了该函数或使用了其名称。

为什么这样做不好?

这会增加代码的阅读难度,并可能造成混淆。

请注意,在函数声明之前,函数就已经可用

示例

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.