OSDN Git Service

【更新内容】
[ring-lang-081/ring.git] / docs / en / target / qtmobile.txt
1 .. index:: 
2         single: Building RingQt Applications for Mobile; Introduction
3
4 =======================================
5 Building RingQt Applications for Mobile
6 =======================================
7
8 In this chapter we will learn about Building RingQt Applications for Mobile.
9
10
11 .. index:: 
12         pair: Building RingQt Applications for Mobile; Download Requirements
13
14 Download Requirements
15 =====================
16
17 Check the next link : http://doc.qt.io/qt-5/androidgs.html
18
19 Download 
20
21 * The Android SDK Tools
22
23         https://developer.android.com/sdk/index.html
24
25 * The Android NDK (Tested using android-ndk-r21)
26
27         http://developer.android.com/tools/sdk/ndk/index.html
28
29 * Java SE Development Kit (JDK) v6 or later
30
31         https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
32
33 .. index:: 
34         pair: Building RingQt Applications for Mobile; Update the Android SDK
35
36 Update the Android SDK
37 ======================
38
39 Update the Android SDK to get the API and tools packages required for development
40
41         Tested using Android 4.4.2 (API 19)
42
43 * In Windows - Define the next Environment Variables based on your system.
44
45 (1) JAVA_HOME
46
47 .. code-block:: ring
48         
49         For Example : C:\Program Files (x86)\Java\jdk1.8.0_05 
50
51 (2) ANDROID_HOME        
52
53 .. code-block:: ring
54
55         For Example : C:\JavaAndroid\AndroidSDK
56
57 .. index:: 
58         pair: Building RingQt Applications for Mobile; Install Qt for Android
59
60 Install Qt for Android
61 ======================
62
63 * You can install Qt for Android from the next link
64
65                 https://download.qt.io/archive/qt/5.12/5.12.6/
66
67 * Run Qt Creator, Select Tools > Options > Android to add the 
68     Android NDK and SDK paths. 
69
70                 http://doc.qt.io/qtcreator/creator-developing-android.html
71
72
73 .. index:: 
74         pair: Building RingQt Applications for Mobile; Using Ring2EXE
75
76 Using Ring2EXE
77 ==============
78
79 We can use Ring2EXE to quickly prepare Qt project for our application
80
81 Example:
82
83 .. code-block:: none
84
85         ring2exe myapp.ring -dist -mobileqt
86
87
88 .. note:: We can use the Distribute Menu in Ring Notepad
89
90 .. tip:: The option ( Prepare Qt project for Mobile devices ) in the Distribute Menu
91
92 .. index:: 
93         pair: Building RingQt Applications for Mobile; The Qt project for your Ring application
94
95 The Qt project for your Ring application
96 ========================================
97
98 After using Ring2EXE or the Distribute Menu in Ring Notepad 
99
100 *  Using the Qt Creator Open the generated Qt project 
101
102         Folder : target/mobile/qtproject
103
104         Project file : project.pro
105
106 * Using Qt Creator, You will find the compiled Ring application in the resources (YourAppName.ringo)
107
108         This file (Ring Object File) is generated by the Ring compiler using
109
110 .. code-block:: none
111
112         ring YourAppName.ring -go -norun
113
114 * You can build your application using Qt Creator
115
116 (1) You can add your application images to the resources
117
118         Or You can use any text editor (Notepad) and modify : project.qrc
119
120 (2) To find images from your Ring application, You need to use the file name in resources
121
122         Example 
123
124 .. code-block:: ring
125
126         if isandroid()
127                 mypic = new QPixmap(":/cards.jpg")
128         else
129                 mypic = new QPixmap("cards.jpg")
130         ok
131
132 .. index:: 
133         pair: Building RingQt Applications for Mobile; Comments about developing for Android using RingQt
134
135 Comments about developing for Android using RingQt
136 ==================================================
137
138 (1) The main project file is main.cpp 
139
140         This file load Ring Compiler/Virtual Machine and RingQt 
141
142         Then get the Ring Object File during the runtime from the resources
143
144         Then run the Ring Object File (ringapp.ringo) using the Ring VM 
145
146         Through main.cpp you can extract more files from the resources to temp. folder once you
147         add them (create projects with many files).
148
149 (2) The next functions are missing from this Ring edition
150
151         * Database (ODBC, SQLite & MySQL)
152
153         * Security and Internet functions (LibCurl & OpenSSL)
154
155         * RingAllegro (Allegro Library)
156
157         * RingLibSDL (LibSDL Library)
158
159         Just use Qt Classes through RingQt.
160
161         For database access use the QSqlDatabase Class
162
163 .. note:: All of the missing libraries ((LibCurl, OpenSSL & Allegro) can be compiled for Android, but they are not included in this Qt project.
164
165 (3) use if isandroid() when you want to modify the code just for android
166
167 Example:
168
169 .. code-block:: ring
170
171         if isandroid()
172                 // Android code
173         else
174                 // other platforms
175         ok
176
177 (4) Sometimes you will find that the button text/image is repeated in drawing !
178 it's Qt problem that you can avoid using the next code.
179
180 .. code-block:: ring
181
182         if isandroid()
183                 setStyleSheet("
184                         border-style: outset;
185                         border-width: 2px;
186                         border-radius: 4px;
187                         border-color: black;
188                         padding: 6px;")
189          ok
190
191 (5)  Always use Layouts instead of manual setting of controls position and size. 
192
193 This is the best way to get the expected user interface to avoid problems like (controls with small/extra size)
194
195 (6) When you deal with Qt Classes you can determine the images from resources (you don't need to copy them using main.cpp)
196
197
198 Example: 
199
200 .. code-block:: ring
201
202         if isandroid()
203             mypic = new QPixmap(":/cards.jpg")
204         else
205             mypic = new QPixmap("cards.jpg")
206         ok
207
208 Now RingQt comes with the AppFile() function to determine the file name 
209
210 Example:
211
212 .. code-block:: ring
213
214         mypic = new QPixmap(AppFile("cards.jpg"))  # Desktop or Android
215
216 (7) When you update your project code, You don't have to use Ring2EXE to generate the Qt project again
217
218 Just use the Distribute Menu in Ring Notepad and select (Generate Ring Object File)
219
220 Then copy the YourAppName.ringo file to target/mobile/qtproject folder and accept replacing files.
221
222 (8) If your application folder contains a Qt resource file (project.qrc)
223
224 Then when you use Ring2EXE or Ring Notepad (Distribute - Prepare Qt project for Mobile devices) the 
225 resource file will be used 
226
227 See ring/applications/cards game as an example.