Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
eval.qdoc
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qmllint-warnings-and-errors-eval.html
6\ingroup qmllint-warnings-and-errors
7
8\title Eval
9\brief [eval] Usage of eval.
10
11\qmllintwarningcategory eval
12
13\section1 Do not use eval
14
15\section2 What happened?
16You used \c {eval} in your code.
17
18\section2 Why is that bad?
19The \c{eval} method is slow and potentially dangerous. \c{eval} executes its
20argument as if it were its own JavaScript script, which adds some overhead to the
21execution. The argument passed to \c{eval} is potentially a vector for remote
22code execution attacks.
23
24\section2 Example
25\qml
26import QtQuick
27
28Item {
29 function f() {
30 let myString = "x",
31 myObject = {
32 x: 10
33 },
34 value = eval("myObject." + myString);
35 }
36}
37\endqml
38To fix this warning, rewrite the code so that it doesn't contain any \c {eval}
39calls.
40\qml
41import QtQuick
42
43Item {
44 function f() {
45 let myString = "x",
46 myObject = {
47 x: 10
48 },
49 value = myObject[myString];
50 }
51}
52\endqml
53*/