QT Mobile Exercise Book
QT Mobile Exercise Book
Workbook
Version 2.5
Prerequisities
The participants should have knowledge on C++ language with basic object oriented features including classes and object, inheritance and virtual methods. Template principles are needed only for understanding Qts collection classes. No STL or RTTI (runtime-type-information) knowledge of standard C++ required.
b) To your project, add a new C++ source file (e.g. main.cpp) and write a basic HelloWorld like application (refer to the lecture slides). c) Build and run the application on different targets e.g. desktop (Linux or Windows), mobile simulator and if available, on MeeGo SDK environment also. d) Try different fonts and font colors to present text in your label component. If you know how to write HTML, you can also modify the component text by writing HTML code inside the text string or the label. e) Modify the application so that there is a QPushButton instead of QLabel. Add functionality where the application exits when the user presses the button. f) Get familiar with the help system of Qt Creator. How can you easily open the api documentation of a specific class? In which situations QPushButton instances send signals? Does the QPushButton class define any slots?
c) Implement the GUI in the widget class constructor by first creating a layout e.g. QVBoxLayout and then the widgets itself one by one. Remember to add your widget class as a parent for the layout and then add the child widgets (QLabel, QLineEdit etc..) to the widget. Remember the proper memory management! d) Create a main.cpp file where you create QApplication instance, create and show your widget and execute the application. Build and run the GUI.
d) Implement the calculation functionality for the application. The body mass index is calculated by the following formula: BMI = weight (kg) / (height(meters) x height(meters))
QAction represents a menu item in menus. QAction sends signal triggered(), when selected by the user. a) Now create a new Qt GUI Application project named MyAnimation. Select QMainWindow to be the base class for your application.
b) To your project, add a new Qt C++ class AnimationWidget inheriting from QWidget.
c) In your QMainWindow class, add an instance of your widget. Create an instance of your animation widget in the constructor. After creating, the must also be set as a central widget for the main window.
//Include the header of your widget class #include AnimationWidget.h //In the class declaration of your main window class private: AnimationWidget* animationWidget; }; // In the constructor of your main window class you create the widget and // set it to be the central widget of this window animationWidget = new AnimationWidget( this ); setCentralWidget( animationWidget );
d) In your main window constructor, implement a menu with the following actions: Start (starts the animation) Stop (stops the animation) Quit (quits the application) e) Implement the Quit action for the application. For the Quit functionality, add a message dialog to ask the user Exit application? with options Yes and No.
a) Implement a simple Mobile Application, which shows the current battery level percentage on a QLcdDisplay component. The UI consists of a single QWidget with QLcdDisplay instance. The battery level API and signals related to it can be found from System Info Mobility APIs. Test the application on the Mobile Simulator. Note! You have to set the build target to be the Simulator, Symbian or Maemo target device in order to get this built). b) Test the application with different battery states, battery low states by using the mobile simulator application. c) If you have a Maemo/MeeGo or a Symbian handset available, deploy and test the application on a target device. Follow the rules you can find from behind the link on the Qt Creators Welcome view (Nokia Qt SDK).
Mobility API Workshop: Where am I? application featuring Location, Google Maps, SMS Messaging and Phonebook.
For multiple views, you can use QStackedWidget component, which can contain multiple QWidgets of which one can be displayed at a time. This is a way of implementing view based applications.
QWidget *firstPageWidget = new QWidget; QWidget *secondPageWidget = new QWidget; QWidget *thirdPageWidget = new QWidget; QStackedWidget *stackedWidget = new QStackedWidget; stackedWidget->addWidget(firstPageWidget); stackedWidget->addWidget(secondPageWidget); stackedWidget->addWidget(thirdPageWidget); // Selecting the current widget stackedWidget->setCurrentIndex(0); // Or stackedWidget->setCurrentWidget( firstPageWidget );
The quickest way to implement multiple views with QStackedWidget is of course using Qt Designer tool. Implement an application, which uses the Location API to determine the current GPS location (latitude and longitude). The location can then be shown on Google Maps and also sent to the specified phone number as an SMS message. Implement the application UI views with Qt Designer by using QStackedWidget component. View1 Location/Google Maps View: When the application gets the location data, it opens Google Maps with the current location by using QWebView (see Google Maps API for how to set the proper URL. View2: SMS Editor View: This view is opened when the user selects to send his/her location via SMS. View3: Contacts view (optional, time permitting). Add a button Contacts to the SMS editor view. The button opens this view to display the contact book contacts, where the user can select the recipient. After confirming, the SMS editor view is opened and the selected contacts phone number is displayed on the recipient field. Optional (time permitting): Open the previously created animated ball exercise and change the implementation so that the ball can be directed with mobile phone sensors. Use Qt Mobility Sensor API to do the task.