值
此警告类别由 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.