Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qjsengine.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
5
8 object.setProperty("num", 42);
9 QJSValue function = engine.evaluate("(o) => o.num *= 2 ");
10 QJSValueList args = { object };
13 Q_ASSERT(result.equals(expected) && !result.strictlyEquals(expected));
14
16
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
QJSValue newObject()
Creates a JavaScript object of class Object.
QJSValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1, QStringList *exceptionStackTrace=nullptr)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
QJSValue call(const QJSValueList &args=QJSValueList()) const
Calls this QJSValue as a function, passing args as arguments to the function, and using the globalObj...
Definition qjsvalue.cpp:681
void setProperty(const QString &name, const QJSValue &value)
Sets the value of this QJSValue's property with the given name to the given value.
Definition qlist.h:74
QJSValue expected
Definition qjsengine.cpp:12
QJSValue function
Definition qjsengine.cpp:9
QJSValueList args
Definition qjsengine.cpp:10
QJSEngine engine
[qjs-engine]
Definition qjsengine.cpp:6
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47