Eval
qmllint 将此警告类别拼写为[eval] 。
请勿使用 eval
发生了什么?
您在代码中使用了 `eval `。
为什么这样做不好?
eval 方法运行缓慢且可能存在安全隐患。eval 会将其参数作为独立的 JavaScript 脚本执行,这会给执行过程增加额外开销。传递给eval 的参数可能成为远程代码执行攻击的载体。
示例
import QtQuick
Item {
function f() {
let myString = "x",
myObject = {
x: 10
},
value = eval("myObject." + myString);
}
}要解决此警告,请重写代码,确保其中不包含任何eval 调用。
import QtQuick
Item {
function f() {
let myString = "x",
myObject = {
x: 10
},
value = myObject[myString];
}
}© 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.