表达式中请勿使用 void
qmllint 将此警告类别标记为[void] 。
请勿使用 void 表达式
发生了什么?
使用了 JavaScript 的 void 表达式。
为什么这样不好?
void 表达式在很大程度上已变得多余,且会因抑制返回值而模糊某些代码的逻辑。此外,由于其不直观且难以阅读,许多代码规范也禁止使用它。
示例
import QtQuick
Item {
function undef() {
return void 0
}
function f() {
return void someFunction()
}
}要解决此警告,请删除或替换 void 的用法:
import QtQuick
Item {
function undef() {
return undefined
}
function f() {
somefunction()
}
}© 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.