不要在表达式中使用 void
该警告类别由 qmllint 拼写为[void]
。
请勿在表达式中使用 void
发生了什么事?
使用了 JavaScript void 表达式。
为什么这样做不好?
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() } }
© 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.