Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_script_qjsvalue.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
9myObject.setProperty("name", "John Doe");
11
12
15engine.evaluate("function fullName() { return this.firstName + ' ' + this.lastName; }");
16engine.evaluate("somePerson = { firstName: 'John', lastName: 'Doe' }");
17
20QJSValue who = global.property("somePerson");
21qDebug() << fullName.call(who).toString(); // "John Doe"
22
23engine.evaluate("function cube(x) { return x * x * x; }");
26args << 3;
27qDebug() << cube.call(QJSValue(), args).toNumber(); // 27
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
QJSValue globalObject() const
Returns this engine's Global Object.
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:705
double toNumber() const
Returns the number value of this QJSValue, as defined in \l{ECMA-262} section 9.3,...
Definition qjsvalue.cpp:526
void setProperty(const QString &name, const QJSValue &value)
Sets the value of this QJSValue's property with the given name to the given value.
QString toString() const
Returns the string value of this QJSValue, as defined in \l{ECMA-262} section 9.8,...
Definition qjsvalue.cpp:494
QJSValue property(const QString &name) const
Returns the value of this QJSValue's property with the given name.
Definition qlist.h:75
QJSValue global
QJSValue myOtherObject
QJSValue fullName
QJSValue cube
QJSValue who
QJSValueList args
QJSEngine myEngine
[0]
QJSEngine engine
[0]
qDebug()<< fullName.call(who).toString()
[1]
QJSValue myObject