逗号

此警告类别由 qmllint 拼写为[comma]

请勿使用逗号表达

发生了什么?

在 for 循环之外使用了 JavaScript 逗号表达式。

为什么这样做不好?

逗号表达式会降低代码的可读性,并掩盖副作用。

示例

import QtQuick

Item {
    Component.onCompleted: init(config, true), enableLogging(categories), run(1000) // millis
}

要修复此警告,可重构代码,为每个操作使用不同的语句。这样,每个副作用都是明确的,而不是作为另一个无关操作的一部分出现:

import QtQuick

Item {
    Component.onCompleted: {
        init(config, true)
        enableLogging(categories)
        run(1000) // millis
    }
}

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