本页内容

使用

该警告类别在 qmllint 中拼写为[with] 。

涉及语句

发生了什么?

使用了 JavaScript 的 `with ` 语句。

这有什么问题?

在分析未限定的标识符时,with 语句可能会导致误报。此外,最新版 JavaScript 标准已将 with 语句标记为弃用。

示例

import QtQuick

Item {
    function f() {
        with (Math) {
            return PI
        }
    }
}

要解决此警告,请将 `with ` 语句替换为解构属性:

import QtQuick

Item {
    function f() {
        const { PI } = Math;
        return PI
    }
}

注意:您 可以在这里找到更多替代方案。

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