Sie sind auf Seite 1von 10

Ring Documentation, Release 1.

TD { text("Sales" ) }
TD { text("Future" ) }
}
next
}
}
write("report.html",mypage.output())

func PrintEvent
printer1 = new qPrinter(0) {
setoutputformat(1)
setoutputfilename("report.pdf")
}
oView {
web.print(printer1)
web.show()
}
system ("report.pdf")

class CustomersReportView

win = new window() {


setwindowtitle("Report Window")
setgeometry(100,100,500,500)
web = new webview(win) {
setgeometry(100,100,1000,500)
loadpage(new qurl("file:///"+
currentdir()+"/report.html"))
}
new pushbutton(win) {
setGeometry(100,20,100,30)
settext("Print")
setclickevent(Method(:PrintEvent))
}
showMaximized()
}

Screen Shot:

57.61. Creating Reports using the WebLib and the GUILib 693
Ring Documentation, Release 1.6

57.61. Creating Reports using the WebLib and the GUILib 694
CHAPTER

FIFTYEIGHT

BUILDING RINGQT APPLICATIONS FOR MOBILE

In this chapter we will learn about Building RingQt Applications for Mobile.

58.1 Download Requirements

Check the next link : http://doc.qt.io/qt-5/androidgs.html


Download
• The Android SDK Tools
https://developer.android.com/studio/index.html
• The Android NDK (Tested using android-ndk-r10c)
https://developer.android.com/ndk/index.html
• Apache Ant v1.8 or later
http://ant.apache.org/bindownload.cgi
• Java SE Development Kit (JDK) v6 or later
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

58.2 Update the Android SDK

Update the Android SDK to get the API and tools packages required for development
Tested using Android 4.4.2 (API 19)
• In Windows - Define the next Environment Variables based on your system.
1. JAVA_HOME
For Example : C:\Program Files (x86)\Java\jdk1.8.0_05

2. ANDROID_HOME
For Example : B:\mahmoud\Tools\Java-Android\adt-bundle-windows-x86-20140702\sdk

695
Ring Documentation, Release 1.6

58.3 Install Qt for Android

• You can install Qt for Android from the next link


https://download.qt.io/archive/qt/5.5/5.5.1/
• Run Qt Creator, Select Tools > Options > Android to add the Android NDK and SDK paths.
http://doc.qt.io/qtcreator/creator-developing-android.html
• Using Qt Creator Open the project
Folder : ring/android/ringqt/project
Project file : project.pro
• Using Qt Creator, You will find the compiled Ring application in resources/ringapp.ringo
This file (Ring Object File) is generated by the Ring compiler using
ring ringapp.ring -go -norun

• To run your application instead of the default application


1. Using Qt Creator, Add your application images to resources
Or You can use any text editor (Notepad) and modify : project.qrc
2. To find images from your Ring application, You need to use the file name in resources
Example
if isandroid()
mypic = new QPixmap(":/cards.jpg")
else
mypic = new QPixmap("cards.jpg")
ok

3. In your Ring application folder (Using the command prompt)


ring myapp.ring -go -norun

4. Add your file to the project project/myapp.ringo


5. Update main.cpp and project.qrc and replace ringapp.ringo with myapp.ringo
6. Build and Run your Application using Qt Creator

58.3. Install Qt for Android 696


Ring Documentation, Release 1.6

58.4 Comments about developing for Android using RingQt

1. The main project file is main.cpp


This file load Ring Compiler/Virtual Machine and RingQt
Then copy the Ring Object File during the runtime from the resources to temp. folder
Then run the Ring Object File (ringapp.ringo) using the Ring VM
Through main.cpp you can extract more files from the resources to temp. folder once you add them
(create projects with many files).
2. The next functions are missing from this Ring edition
• Database (ODBC, SQLite & MySQL)
• Security and Internet functions (LibCurl & OpenSSL)
• RingAllegro (Allegro Library)
• RingLibSDL (LibSDL Library)
Just use Qt Classes through RingQt.
For database access use the QSqlDatabase Class

Note: All of the missing libraries ((LibCurl, OpenSSL & Allegro) can be compiled for Android, but they are not
included in this Qt project.

3. use if isandroid() when you want to modify the code just for android
Example:
if isandroid()
// Android code

58.4. Comments about developing for Android using RingQt 697


Ring Documentation, Release 1.6

else
// other platforms
ok

(4) Sometimes you will find that the button text/image is repeated in drawing ! it’s Qt problem that you can avoid
using the next code.
if isandroid()
setStyleSheet("
border-style: outset;
border-width: 2px;
border-radius: 4px;
border-color: black;
padding: 6px;")
ok

5. Always use Layouts instead of manual setting of controls position and size.
This is the best way to get the expected user interface to avoid problems like (controls with small/extra size)
6. When you deal with Qt Classes you can determine the images from resources (you don’t need to copy them
using main.cpp)
Example:
if isandroid()
mypic = new QPixmap(":/cards.jpg")
else
mypic = new QPixmap("cards.jpg")
ok

Now RingQt comes with the AppFile() function to determine the file name
Example:
mypic = new QPixmap(AppFile("cards.jpg")) # Desktop or Android

58.5 Using Ring2EXE

Starting from Ring 1.6 we can use Ring2EXE to quickly prepare Qt project for our application
Example:
ring2exe myapp.ring -dist -mobileqt

58.5. Using Ring2EXE 698


CHAPTER

FIFTYNINE

OBJECTS LIBRARY FOR RINGQT APPLICATION

In this chapter we will learn about the objects library for RingQt applications.
Ring comes with the Objects library for RingQt applications. Instead of using global variables for windows objects
and connecting events to objects using the object name, the Objects Library will manage the GUI objects and will
provide a more natural API to quickly create one or many windows from the same class and the library provide a way
to quickly set methods to be executed when an event is fired. Also the library provide a natural interface to quickly
use the parent or the caller windows from the child or sub windows.
The Objects Library is designed to be used with the MVC Design Pattern.
The Objects Library is merged in RingQt so you can use it directly when you use RingQt

59.1 Library Usage

• Use the Open_Window(cWindowControllerClassName) function to open new Windows


• Create at least Two Classes for each window, The Controller Class and the View Class
• Create each controller class from the WindowsControllerParent Class
• Create each view class from the WindowsViewParent Class
• Use the Last_Window() function to get the object of the last window created (The Controller object).
• When you call a sub window, use the SetParentObject() method and pass the self object.
• In the View Class, To determine the event method use the Method(cMethodName) function.
• The Method(cMethodName) function determine the method in the controller class that will be executed.
• Each controller class contains by default the CloseAction() method that you can call to close the window.
• You don’t need to call the Show() Method for each window, When you use Open_Window() It will be called.
• In the view class, Define the GUI window object as an attribute called win.
• You can use Open_WindowNoShow() to avoid displaying the window.
• You can use Open_WindowAndLink() to quickly get methods to access the windows.

59.2 Example

In the next example we will create two types of windows.


• Main Window contains a button. When the user click on the button a sub window will be opened.

699
Ring Documentation, Release 1.6

• The User Can click on the button many times to open many sub windows.
• Each Sub Window contains Two buttons.
• The first button in the sub window change the Main and the Sub Windows Titles.
• The second button in the sub window close the Sub Window.
load "guilib.ring"

new qApp {
open_window( :MainWindowController )
exec()
}

class MainWindowController from WindowsControllerParent


oView = new MainWindowView
func SubWindowAction
Open_window( :SubWindowController )
Last_Window().SetParentObject(self)

class MainWindowView from WindowsViewParent


win = new qWidget() {
SetWindowTitle("Main Window")
btnSub = new qPushButton(win) {
setText("Sub Window")
setClickEvent( Method( :SubWindowAction ) )
}
resize(400,400)
}

class SubWindowController from WindowsControllerParent


oView = new SubWindowView
func SetMainWindowTitleAction
Parent().oView.win.SetWindowTitle("Message from the Sub Window")
oView.win.SetWindowTitle("Click Event Done!")

class SubWindowView from WindowsViewParent


win = new qWidget() {
SetWindowTitle("Sub Window")
btnMsg = new qPushButton(win) {
setText("Set Main Window Title")
setClickEvent( Method( :SetMainWindowTitleAction ) )
}
btnClose = new qPushButton(win) {
Move(200,0)
setText("Close")
setClickEvent( Method( :CloseAction ) )
}
resize(400,400)
}

The next screen shot after creating three sub windows.

59.2. Example 700


Ring Documentation, Release 1.6

The next screen shot after clicking on the button in each sub window.

59.2. Example 701


Ring Documentation, Release 1.6

59.3 Open_WindowAndLink() Function

We can use the Open_WindowAndLink() function to connect between the application windows, pass messages (call
methods) between the objects.
This function uses Meta-programming to define dynamic methods in the Caller Class to use the dynamic objects of
other windows that we create.
Example : (Uses the Form Designer)
First Window
1. https://github.com/ring-lang/ring/blob/master/applications/formdesigner/tests/twowindowspart5/firstwindowView.ring
2. https://github.com/ring-lang/ring/blob/master/applications/formdesigner/tests/twowindowspart5/firstwindowController.ring
Second Window
1. https://github.com/ring-lang/ring/blob/master/applications/formdesigner/tests/twowindowspart5/secondwindowView.ring
2. https://github.com/ring-lang/ring/blob/master/applications/formdesigner/tests/twowindowspart5/secondwindowController.ring

59.3. Open_WindowAndLink() Function 702

Das könnte Ihnen auch gefallen