该警告类别由 qmllint 拼写[with]

与声明

发生了什么事?

使用了 JavaScriptwith 语句。

为什么会这样?

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

示例

import QtQuick

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

要修复此警告,请将with 语句替换为析构属性:

import QtQuick

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

注: 您可以在此处找到更多替换方法。

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