QtQuickAppDevIntro.pdf

(2726 KB) Pobierz
Introduction to Application
Development with Qt Quick
Release1.0
Digia, Qt Learning
February 28, 2013
Contents
1Introduction
1
1.1
Who should read this tutorial and why . . . . . . . . . . . . . . . . . . . . . .
1
1.2
The journey is the target
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1.3
Downloads
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1.4
Help us help you . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1.5
Related material
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1.6
License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
2WorkEnvironmentSetup
5
2.1
Installing the tools
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
2.2
Creating Qt Quick applications
. . . . . . . . . . . . . . . . . . . . . . . . .
5
2.3
Qt Quick Application* project type
. . . . . . . . . . . . . . . . . . . . . . .
7
2.4
Tracing what is going on . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
3QtQuickCorePrinciplesforApplicationDevelopment
11
3.1
Qt Quick Compared to Classical Qt
. . . . . . . . . . . . . . . . . . . . . . .
11
3.2
Declarative vs imperative programming . . . . . . . . . . . . . . . . . . . . .
12
3.3
Four cornerstones
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
3.4
Moving from a concept to a real application . . . . . . . . . . . . . . . . . . .
14
4Elementsasbuildingblocks
17
4.1
Composing a basic UI with nested elements . . . . . . . . . . . . . . . . . . .
17
4.2
Ordering elements on the screen . . . . . . . . . . . . . . . . . . . . . . . . .
19
4.3
Arranging application elements on the screen . . . . . . . . . . . . . . . . . .
20
4.4
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
4.5
Other Visual Composition Elements . . . . . . . . . . . . . . . . . . . . . . .
27
5LoadingandDisplayingContent
29
5.1
Accessing and loading content . . . . . . . . . . . . . . . . . . . . . . . . . .
29
5.2
Basic Image Parameters
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
30
5.3
Basic Text Parameters
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
31
i
1299929616.001.png 1299929616.002.png
 
5.4
Get ready for translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
32
5.5
Static Clock Application Code . . . . . . . . . . . . . . . . . . . . . . . . . .
33
6UsingJavaScript
36
6.1
JavaScript is not JavaScript
. . . . . . . . . . . . . . . . . . . . . . . . . . .
36
6.2
More About JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
37
6.3
Adding Logic to Make the Clock Tick . . . . . . . . . . . . . . . . . . . . . .
37
6.4
Importing JavaScript Files . . . . . . . . . . . . . . . . . . . . . . . . . . . .
41
7AcquireandVisualizeData
44
7.1
Models
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
44
7.2
Repeater and Views
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
47
8ComponentsandModules
53
8.1
Creating Components and Collecting Modules
. . . . . . . . . . . . . . . . .
53
8.2
Defining Interfaces and Default Behavior
. . . . . . . . . . . . . . . . . . . .
54
8.3
Handling Scope
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
55
8.4
Integrated Application
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
58
8.5
Further Readings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
62
9InteractiveUIwithMultipleTop-LevelWindows
63
9.1
A Button
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
63
9.2
A Simple Dialog
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
66
9.3
A Checkbox
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
69
9.4
Handling Keyboard Input and Navigation . . . . . . . . . . . . . . . . . . . .
70
10UIDynamicsandDynamicUI
77
10.1
Using States
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
77
10.2
Adding Animations
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82
10.3
Supporting the Landscape Mode . . . . . . . . . . . . . . . . . . . . . . . . .
84
10.4
Finalizing the Main Item . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
85
11DoingMore,LearningMore
91
11.1
Porting to Qt5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
91
11.2
Porting to a mobile device
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
91
11.3
Enhancements and New Features
. . . . . . . . . . . . . . . . . . . . . . . .
93
12LessonLearnedandFurtherReading
95
13Annexure:JavaScriptLanguageOverview
97
13.1
Introduction
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
97
13.2
The Type System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
98
13.3
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
99
13.4
Branching
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
99
13.5
Repetitions and Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
99
13.6
Labeled Loops, Break and Continue . . . . . . . . . . . . . . . . . . . . . . . 100
13.7
Objects and Functions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
13.8
Prototype-based Inheritance
. . . . . . . . . . . . . . . . . . . . . . . . . . . 101
13.9
Scopes, Closures and Encapsulation . . . . . . . . . . . . . . . . . . . . . . . 104
ii
13.10 Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
13.11 Common Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
13.12 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
13.13 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
iii
iv
Zgłoś jeśli naruszono regulamin