Beruflich Dokumente
Kultur Dokumente
09/25/09
Agenda
What is application scripting? QtScript tour (the essentials) Debugger Misc.
What is QtScript?
A Qt module A scripting language An engine for evaluating scripts An API for embedding into your application
Disclaimer
This is not a JavaScript tutorial!
10
11
12
Agenda
What is application scripting? QtScript tour (the essentials) Debugger Misc.
13
14
Our objective: Write an application that uses QtScript to calculate the meaning of life
15
QScriptEngine object
QScriptEngine engine; Vanilla environment Built-in ECMA objects Array, Math, RegExp, Error, ... parseInt(), parseFloat(), ... No Qt-specific script APIs
16
17
18
19
QScriptValue class
Represents a QtScript (JavaScript) value Undefined Null Boolean Number String Object Functions, arrays, regexps, errors, ... Invalid (no value)
20
21
QScriptValue construction
Constructors for standard Qt/C++ types qScriptValueFromValue() Counterpart to qscriptvalue_cast() QScriptEngine::newXXX() Object, QObject, Array, RegExp
22
23
24
25
26
27
28
29
30
QScriptValueIterator class
QScriptValueIterator it(myObject); while (it.hasNext()) { it.next(); qDebug() << it.name(); }
31
32
33
34
35
36
37
38
39
JS:
var myMeaningOfLife = Math.sqrt(meaningOfLife);
40
41
42
Qt Meta-Object System
In Qt, QObject-based classes can be introspected at runtime Properties Signals & slots QObject::connect() Qt Designer property editor ...
43
44
45
46
47
48
qScriptConnect() function
Connect a signal to a script function Let scripts define signal handlers Application does the plumbing
49
50
Agenda
What is application scripting? QtScript tour (the essentials) Debugger Misc.
51
52
Debugger Demo
Look at the pretty little demo!
53
54
55
56
Agenda
What is application scripting? QtScript tour (the essentials) Debugger Misc.
57
Prototypes...?
58
59
60
61
62
63
Summary
It's easy to make your Qt application scriptable with QtScript There's a QtScript debugger (also part of Qt) You can achieve a lot by mastering a small API
64
Thank You!
Questions?
65