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]
5
QJSEngine
myEngine
;
6
QJSValue
myObject
= myEngine.newObject();
7
QJSValue
myOtherObject
= myEngine.newObject();
8
myObject.setProperty(
"myChild"
, myOtherObject);
9
myObject.setProperty(
"name"
,
"John Doe"
);
10
//! [0]
11
12
13
//! [1]
14
QJSEngine
engine
;
15
engine.evaluate(
"function fullName() { return this.firstName + ' ' + this.lastName; }"
);
16
engine.evaluate(
"somePerson = { firstName: 'John', lastName: 'Doe' }"
);
17
18
QJSValue
global
= engine.globalObject();
19
QJSValue
fullName
= global.property(
"fullName"
);
20
QJSValue
who
= global.property(
"somePerson"
);
21
qDebug() << fullName.call(who).toString();
// "John Doe"
22
23
engine.evaluate(
"function cube(x) { return x * x * x; }"
);
24
QJSValue
cube
= global.property(
"cube"
);
25
QJSValueList
args
;
26
args << 3;
27
qDebug() << cube.call(QJSValue(), args).toNumber();
// 27
28
//! [1]
myObject
MyClass myObject
[0]
Definition
src_corelib_thread_qfuturewatcher.cpp:6
args
QJSValueList args
Definition
src_script_qjsengine.cpp:12
myEngine
QJSEngine myEngine
[0]
Definition
src_script_qjsengine.cpp:5
global
QJSValue global
Definition
src_script_qjsvalue.cpp:18
cube
QJSValue cube
Definition
src_script_qjsvalue.cpp:24
myOtherObject
QJSValue myOtherObject
Definition
src_script_qjsvalue.cpp:7
fullName
QJSValue fullName
Definition
src_script_qjsvalue.cpp:19
who
QJSValue who
Definition
src_script_qjsvalue.cpp:20
engine
QJSEngine engine
[0]
Definition
src_script_qjsvalue.cpp:14
qtdeclarative
src
qml
doc
snippets
code
src_script_qjsvalue.cpp
Generated on Thu Nov 14 2024 00:47:51 for Qt by
1.12.0