Last change
on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago |
Initially imported qt-all-opensource-src-4.5.1 from Trolltech.
|
File size:
1.1 KB
|
Line | |
---|
1 | //! [0]
|
---|
2 | QScriptEngine myEngine;
|
---|
3 | QScriptValue myObject = myEngine.newObject();
|
---|
4 | QScriptValue myOtherObject = myEngine.newObject();
|
---|
5 | myObject.setProperty("myChild", myOtherObject);
|
---|
6 | myObject.setProperty("name", "John Doe");
|
---|
7 | //! [0]
|
---|
8 |
|
---|
9 |
|
---|
10 | //! [1]
|
---|
11 | QScriptValue val(&myEngine, 123);
|
---|
12 | myObject.setProperty("myReadOnlyProperty", val, QScriptValue::ReadOnly);
|
---|
13 | //! [1]
|
---|
14 |
|
---|
15 |
|
---|
16 | //! [2]
|
---|
17 | QScriptEngine engine;
|
---|
18 | engine.evaluate("function fullName() { return this.firstName + ' ' + this.lastName; }");
|
---|
19 | engine.evaluate("somePerson = { firstName: 'John', lastName: 'Doe' }");
|
---|
20 |
|
---|
21 | QScriptValue global = engine.globalObject();
|
---|
22 | QScriptValue fullName = global.property("fullName");
|
---|
23 | QScriptValue who = global.property("somePerson");
|
---|
24 | qDebug() << fullName.call(who).toString(); // "John Doe"
|
---|
25 |
|
---|
26 | engine.evaluate("function cube(x) { return x * x * x; }");
|
---|
27 | QScriptValue cube = global.property("cube");
|
---|
28 | QScriptValueList args;
|
---|
29 | args << 3;
|
---|
30 | qDebug() << cube.call(QScriptValue(), args).toNumber(); // 27
|
---|
31 | //! [2]
|
---|
32 |
|
---|
33 |
|
---|
34 | //! [3]
|
---|
35 | QScriptValue myNativeFunction(QScriptContext *ctx, QScriptEngine *)
|
---|
36 | {
|
---|
37 | QScriptValue otherFunction = ...;
|
---|
38 | return otherFunction.call(ctx->thisObject(), ctx->argumentsObject());
|
---|
39 | }
|
---|
40 | //! [3]
|
---|
Note:
See
TracBrowser
for help on using the repository browser.