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
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
4//! [0]
6QJSValue myObject = myEngine.newObject();
7QJSValue myOtherObject = myEngine.newObject();
8myObject.setProperty("myChild", myOtherObject);
9myObject.setProperty("name", "John Doe");
10//! [0]
11
12
13//! [1]
15engine.evaluate("function fullName() { return this.firstName + ' ' + this.lastName; }");
16engine.evaluate("somePerson = { firstName: 'John', lastName: 'Doe' }");
17
18QJSValue global = engine.globalObject();
19QJSValue fullName = global.property("fullName");
20QJSValue who = global.property("somePerson");
21qDebug() << fullName.call(who).toString(); // "John Doe"
22
23engine.evaluate("function cube(x) { return x * x * x; }");
24QJSValue cube = global.property("cube");
26args << 3;
27qDebug() << cube.call(QJSValue(), args).toNumber(); // 27
28//! [1]
QJSValueList args
QJSEngine myEngine
[0]
QJSValue global
QJSValue cube
QJSValue myOtherObject
QJSValue fullName
QJSValue who
QJSEngine engine
[0]