Você está na página 1de 176

Qt Workshop

Senior Software Specialist Tino Pyssysalo @digia.com Digia Plc.

Workshop Objectives
To get a really good overview on
What is Qt development especially on mobile platforms
QtMobility APIs

How do you work with the new Nokia N8

To go technical enough
To actually be able to start doing something meaningful after the course! Qt is C++, so prior C++ knowledge is required

If you have any questions at any point, please do not hesitate to ask! For more information:
http://www.forum.nokia.com http://developer.qt.nokia.com
2

Qt for N8 - Digia Plc

Schedule Estimate
Practicalities, Qt Mobile Overview & Status Nokia Qt SDK Free Ovi Store Symbian Signing Smart Installer and Publishing to Ovi Store Qt essentials

Lunch, 12:30 13:30


3

Qt Animation Framework Qt GraphicsView Creating Outstanding UIs with QtQuick Porting iPhone / Android apps to Qt Qt Mobility APIs

Qt for N8 - Digia Plc

Required Tools
Laptop:
Qt for Desktop (windows/linux/mac) Nokia Qt SDK
includes QtMobility APIs includes Qt for Symbian includes Qt Creator IDE

Symbian Device (if you have):


Qt libraries Qt Mobility libraries TRK application

Qt for N8 - Digia Plc

Course Material
Please copy the material from the USB stick Contains:
Course slides Exercise book Exercise solutions A few additional sample applications

A few N8 devices available for you to try out during the hands-on exercises!

Qt for N8 - Digia Plc

Qt Overview
Qt Status for Mobile Devices

What is Qt?

Qt for N8 - Digia Plc

Cross-Platform APIs
Cross-platform Qt APIs are wrappers around native services
Application 1 Application 2 Application 3

Qt APIs Qt

Qt/Windows Win32 GDI Windows Kernel

Qt/Mac Carbon / Cocoa Mac HW

Qt/Symbian S60 / OpenC Symbian

Qt for N8 - Digia Plc

Different Qt Platforms

One and unified Cross-Platform API

Qt/X11

Qt/MeeGo

Qt/Win

Qt/Mac

Qt/Embedded Qt/WinCE Qt/Symbian Linux

Qt for N8 - Digia Plc

What is Symbian^3, or new Symbian?

Symbian development

source: developer.symbian.org

10

Qt for N8 - Digia Plc

Symbian in N8
Its the newest Symbian platform that
Is based on Symbian^1 (and ^2) that back then was S60 5th ed. => Symbian with touch screen Supports Qt Has an UI framework made still with AVKON (S60 UI FW) The new Nokia N8 is using, and the forthcoming ones

11

Qt for N8 - Digia Plc

Qt Developer Offering
Qt Quick, Qt Quick Components

UI
QtDeclarative QtWebkit

QtSvg

QtGUI

QtOpenGL

Engine

Qt
QtScript QtSql QtXml QtMultimedia QtCore QtXmlPatterns QtNetwork

85% of use cases **

Mobile Features Low level Native access


Native APIs

Qt Mobility APIs

Symbian C++
Open C / POSIX

Linux C/C++ libraries

15% of use cases **

Desktop OSs

Symbian Symbian

Linux MeeGo

12

Qt for N8 - Digia Plc

Whats New with the Latest Symbian


Multiple home screens Multi point touch HD TV Improved multitasking Improved graphics architecture Qt included

13

Qt for N8 - Digia Plc

What is MeeGo?

Moblin

Maemo

14

Qt for N8 - Digia Plc

MeeGo Architecture
Netbook UX
Netbook UI + Apps Netbook UI Framework
QtCore, QtGui, QtNetwork, Qt Mobility APis, etc

Qt Quick

Handset UX

Handset UI + Apps Handset UI Framework Qt

MeeGo API
Media Services
Media FW GStreamer Camera GStreamer plug-in Codecs GStreamer plug-in Audio PulseAudio UPnP GUPnP

Comms Services
Connection Mgmt ConnMan Telephony oFono VOIP, IM, Pres Telepathy Bluetooth BlueZ

Internet Services
Layout Engine WebKit Web Run-Time WebKit Web Services Lib SocialWeb Location GeoClue

Visual Services
3D Graphics OpenGL / ES 2D Graphics Cairo, QPainter I18n Rendering Pango, QText GTK /Clutter

Data Mgmt
Content Framework Tracker Context Framework ContextKit Package Manager PackageKit

Device Services
Device Health

Personal Services
PIM Services

Sensor Framework

Device Sync

Resource Manager

Accts & SSO

Backup & Restore

Settings Database GConf


15

Platform Info libudev


Qt for N8 - Digia Plc

Message Bus D-Bus

System Libraries glibc, glib

MeeGo Kernel

Working with Qt on Mobile Devices


Nokia Qt SDK is the easiest approach
Full IDE, QtCreator All Nokia SDKs Qt Simulator ODD

16

Qt for N8 - Digia Plc

Install Qt, Get What?


~15 modules
~ 700 API classes

Build Tools
Configure, Qmake, Moc, Uic and Rcc

Development Tools
Qt Creator, Qt Designer, Qt Assistant, Qt Linguist

QtOpenGl

QtOpenVG

QtSvg

QtWebKit

QtXmlPatterns

Qt3Support QtMobility APIs

QtGui

QtSql

QtXml

QtNetwork

QtScript

Phonon

QtMultimedia

QtCore

17

Qt for N8 - Digia Plc

New Features in Qt 4.7(.1)


Qt Quick, the Qt Ui Creation Kit
QML, a declarative, JS-like, language for designers and developers for creating animated and fluid User Experience QtDeclarative, a C++ library to integrate QML declarations into the Qt Graphics View QtCreator 2.1 supports QML editing

New networking possibilities


Bearer management from Qt Mobility integrated

18

Qt for N8 - Digia Plc

Things Expected Later


Quite a bunch of new Mobility APIs Qt Quick Designer (Dragndrop editor for QML) finalized Qt Quick Components QtWebkit constantly improved (HTML5 etc)

19

Qt for N8 - Digia Plc

Nokia Qt SDK

20

Nokia Qt SDK
Since 4/2010 the Nokia Qt SDK has been available for all Qt related development
Windows Linux, Mac (remote compilation)

Includes
Qt for Symbian and Maemo (4.6.3) QtMobility APIs 1.0.2 Qt Creator IDE 2.0 Qt Simulator ODD for all devices

21

Qt for N8 - Digia Plc

Purpose of Nokia Qt SDK


All Nokia platforms under same tool
Install once, deploy everywhere

Compile Execute Debug applications for all Nokia devices by just one click Provides quick-test tool for mobile UI / mobile events
Qt Simulator

22

Qt for N8 - Digia Plc

Installing Nokia Qt SDK


http://www.forum.nokia.com/Develop/Qt/Tools/
-> Nokia Qt SDK

After installation, check updates from the tool


Often updated!

Self-contained package includes


Qt 4.6.3 SDKs for Symbian, Maemo and Qt Simulator (desktop) QtCreator

So, if you want to do builds for regular desktop


Install normal Qt SDK (for your desktop OS) Works with the Nokia Qt SDK QtCreator as well!

23

Qt for N8 - Digia Plc

Creating New Mobile Projects

24

Qt for N8 - Digia Plc

Target Platforms
All your Qt target platforms are visible in the project wizard You can more targets later to your project

25

Qt for N8 - Digia Plc

Generated .pro file


The New Qt Mobile Project wizard generates a .pro file suitable for mobile projects but otherwise the generated project is rather same than a normal Qt GUI Project

26

Qt for N8 - Digia Plc

Work Flow

2. Code Logic 1. Design UI

3. Try in Qt Simulator

4. Plug in device(s) and select target

27

Qt for N8 - Digia Plc

Work Flow

2. Code Logic 1. Design UI

3. Try in Qt Simulator

4. Plug in device(s) and select target

5. Press Play and be amazed of your Awesomeness!


Qt for N8 - Digia Plc

28

Qt Simulator
Try out UI in phone LAF Simulate mobile events Only for quick-testing!

29

Qt for N8 - Digia Plc

Configuring the Devices


The first time, youll need
For symbian, install TRK (comes with SDK), for ODD For maemo, configure MADDE connection For any device, install Qt (+ QtMobility) libraries
Or! Use smart-installer

Find Getting Started with Nokia Qt SDK documentation for instructions

OVI Suite (or older PC Suite) is also required for the data connection between Nokia device and your device

30

Qt for N8 - Digia Plc

Connecting the Device


Connect with USB and
In Symbian, launch TRK In Maemo, launch MADDE

31

Qt for N8 - Digia Plc

Free Ovi Store Symbian Signing

32

Symbian Platform Security


All Symbian processes need capabilities in order to access secured services
Platform is secure

Qt/Symbian applications are Symbian processes from the OSs point of view
Need capabilities for accessing secured services!

Many services provided by Qt Mobility APIs are secured services

33

Qt for N8 - Digia Plc

What Capabilities Are There?

http://developer.symbian.org/wiki/index.php/Capabilities_(Symbian_Signed)

34

Qt for N8 - Digia Plc

How to Gain Capabilities?


.pro file:
TARGET.CAPABILITY += <capabilities> (Inside symbian { Like: TARGET.CAPABILITY += Location NetworkServices })

Application needs to be signed


Self-signing works for lightest capabilities (user grants) Symbian signed online for a bit heavier capabilities

35

Qt for N8 - Digia Plc

Capabilities and Publishing


Signing publishable applications has been made dramatically easier You can have Ovi publishing do the signing for you
If User or System capabilities Free signing! (ok, registering is 1)

Private publishers do not need a published ID

36

Qt for N8 - Digia Plc

Smart Installer
Publishing to Ovi Store

37

Smart Installer
Your killer Qt app

Nokia N8 (Qt-ready!)

???

Market of Zillions of S60 phones, BUT yet without Qt libraries

38

Qt for N8 - Digia Plc

Smart Installer
Your killer Qt app

Nokia N8 (Qt-ready!)

Smart Installer

Market of Zillions of S60 phones, BUT yet without Qt libraries

39

Qt for N8 - Digia Plc

Smart Installer

Your killer Qt app

Check requirements
Smart Installer

Distribution .sis package

Download and install missing requirements Smart Installer server


40

Qt for N8 - Digia Plc

Packages distributed by Smart Installer (Nov. 2010)

For updated version, see http://wiki.forum.nokia.com/index.php/Nokia_Smart_Installer_for_Symbian

41

Qt for N8 - Digia Plc

Using Smart Installer Concretely


Smart Installer is included in the Nokia Qt SDK qmake creates a Makefile target install_sis which integrates the smart installer with your .sis package Smart installer can be included both for self-signed and Symbian-signed applications:
<Normal compilation with Qt/Symbian tools>

C:\Sources\Application> qmake C:\Sources\Application> make release-gcce

Self-sign:
C:\Sources\Application> make install_sis

Symbian Signed:
<first create signed sis>

C:\Sources\Application> make sis QT_SIS_CERTIFICATE=publisherid.cer QT_SIS_KEY=publisherid.key


<submit created .sis to Symbian Signed, receive new application.sis, create signed wrapper package>

C:\Sources\Application> make install_sis QT_SIS_CERTIFICATE=publisherid.cer QT_SIS_KEY=publisherid.key


<re-submit to Symbian Signed with Express Signed>

42

Qt for N8 - Digia Plc

Qt and the Nokia N8

Qt 4.6.3 (4.6.4) pre-installed Second wave of devices will have Qt 4.7 Capasitive touch screen Multi-touch and Gestures work A GPU! HW accelerated graphics usable with QtOpenVG rasterization mode

43

Qt for N8 - Digia Plc

Qt Essentials

44

Lets Start with a Really Brief Intro to Programming with Qt


Cross-platform Qt APIs are wrappers around native services
Application 1 Application 2 Application 3

Qt APIs Qt

Qt/Windows Win32 GDI Windows Kernel

Qt/Mac Carbon / Cocoa Mac HW

Qt/Symbian S60 / OpenC Symbian

45

Qt for N8 - Digia Plc

Forget Native Code, We Will Code Qt:


Heavily object based C++ Hundreds of ready-made classes, names start with Q High abstraction level UIs built from widgets, items in the graphics view or using Qt Quick SignalsnSlots, used for Object-to-object communication observer pattern Meta-Objects
And QObject as a common base class

Parent and Child Objects


Memory management, window sharing

Has similarities to Java


BUT is still C++!

46

Qt for N8 - Digia Plc

Few Qt Fundamentals More Deeply


Signals & Slots GUI Applications and layout managers Creating custom widgets using Qt Designer

47

Qt for N8 - Digia Plc

First, a Small GUI Example Slider


window
int main( int argc, char** argv ) { QApplication app( argc, argv ); QWidget window; QLCDNumber* lcd = new QLCDNumber( &window ); QSlider* slider = new QSlider( Qt::Horizontal, &window ); window.showMaximized(); // or show() return app.exec(); }

lcd

slider

48

Qt for N8 - Digia Plc

Signals and Slots


Observer pattern Type-safe callbacks
More secure than callbacks, more flexible than virtual methods

Many-to-many relationship Implemented in QObject


Requires meta-object (macro Q_OBJECT)

49

Qt for N8 - Digia Plc

Signals
A signal is a way to inform a possible observer that something of interest has happened inside the observed class
A QPushButton is clicked
QPushButton::clicked()

An asynchronous service handler is finished


QNetworkAccessManager::finished( QNetworkReply* reply )

Value of QSlider is changed (and the new value is informed as a parameter)


QSlider::valueChanged( int )

Signals are member functions that are automatically implemented in the metaobject
Only the function declaration is provided by the developer

Signal is sent, or emitted, using the keyword emit


emit clicked(); emit someSignal(7, Hello);

50

Qt for N8 - Digia Plc

Slots
A slot is a function that is to be executed when a signal has been emitted.
(When QPushButton is clicked), close QDialog (When service is ready), ask for the value and store it (When QSlider value is changed), display the value in QLCDNumber

A Slot function is a normal member function implemented by the developer

51

Qt for N8 - Digia Plc

Signal and Slot Implementation


class NewClass : public QObject { Q_OBJECT // Meta-object file needed // Code convention recommends Q_OBJECT use always, // otherwise qobject_cast fails signals: // Implementation in the meta-object void newSignal(int myInt, QString myString); void anotherSignal(); public slots: // Slots are implemented as normal member functions void newSlot(int i, QString s); void someSlot(); }

52

Qt for N8 - Digia Plc

Connections
To receive a signal in a slot, signal and slot must be connected
bool success = QObject::connect( senderObject, SIGNAL(valueChanged(int)), observerObject, SLOT(display(int)));

Emitted signal results


In an immediate slot function call, if signal and slot implemented in objects in the same thread

Signal and slot signatures must match (signal may have more parameters)
No compile time error checking is made!

53

Qt for N8 - Digia Plc

Events vs. Signals


Some Object
1. User presses button in UI
slot function

Some Object
slot function

Some Object
2. Event is generated and delivered for the corresponding objects event handler function
QEvent (mouse press)

4. Previously connected slot functions get called

slot function

Hey! Im
Event handler

QPushButton object clicked()


3. Pushbutton emits a signal clicked() to shout out loud of the situation

54

Qt for N8 - Digia Plc

Events vs. Signals


So, if you CREATE your own widgets
Hey! Im clicked() MyWidget

Event handler Event handler Event handler

You create event handlers:


What does this widget do when someone clicks it? What does it do when keyboard is pressed? What does it do when it is requested to paint itself (i.e. how does it paint itself)?

You also tell, when does it emit signals

55

Qt for N8 - Digia Plc

Events vs. Signals


Hey! Some Object
slot function

If you USE existing widgets


SomeWidget

valueChanged()

Hey! Im clicked()

Some Object
slot function

You are interested in existing signals


What do I want to do (somewhere else) when the widget is clicked()?

You connect slot functions to the signals

56

Qt for N8 - Digia Plc

Slider Example Continued

1. Slider is moved (to value 21)

2. emit valueChanged(21)
int main( int argc, char** argv ) { QApplication app( argc, argv ); QWidget window; QLCDNumber* lcd = new QLCDNumber( &window ); QSlider* slider = new QSlider( Qt::Horizontal, &window ); QObject::connect( slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int))); window.showMaximized(); return app.exec(); }

3. display(21)

57

Qt for N8 - Digia Plc

Slider Example Result

Application works, but is not exactly what was intented Maybe a layout manager would be nice to add!

58

Qt for N8 - Digia Plc

Slider Example Layout Manager


int main( int argc, char** argv ) { QApplication app( argc, argv );

window
QWidget window; QVBoxLayout* layout = new QVBoxLayout( &window ); QLCDNumber* lcd = new QLCDNumber( &window ); QSlider* slider = new QSlider( Qt::Horizontal, &window ); layout->addWidget( lcd ); layout->addWidget( slider );

layout

lcd
QObject::connect( slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int))); window.showMaximized(); return app.exec(); }

slider

59

Qt for N8 - Digia Plc

Small GUI Example w/ Layout Result

OK, seems to work now!

60

Qt for N8 - Digia Plc

Summary on Qt Basics
Tree of Objects One main widget acts as the parent Signals and slots are used for making objects interact with each other Layout managers used instead of hard coded positions

Do we always need to code the whole GUI?


Nope! Lets check Qt Designer!

61

Qt for N8 - Digia Plc

Qt Designer
Comes with Desktop Qt as a separate application
Also integrated to Carbide.c++ and QtCreator, as Form Designer

Dragndrop UI designer Outputs XML-based .ui files .ui files are converted automatically to .h files by uic (ui compiler)
myproject.ui -> ui_myproject.h

62

Qt for N8 - Digia Plc

Slider Example in Qt Designer


Add widgets with dragndrop Set Layout Modify widget properties Edit Signals&Slots

63

Qt for N8 - Digia Plc

Editing Signals & Slots in Qt Designer


You can connect existing signals & slots in the graphical S&S editor

64

Qt for N8 - Digia Plc

What Does Qt Designer Output?


Qt Designer directly manipulates a .ui file, which is XML uic will (automatically) compile the .ui file into a c++ header file
ui_classname.h Holds a UI Configuration class Ui::ClassName with function setupUi that initializes an existing main window

UI Class

initialize with setupUi()

QMainWindow

65

Qt for N8 - Digia Plc

How to Use the Generated UI Code?


Direct approach
Simple, but no possibility to extend functionality with custom slots No means to validate input data etc.

Single inheritance
Extend functionality with custom slots

66

Qt for N8 - Digia Plc

Direct Approach
In the .pro file, add FORMS += Slider.ui
#include ui_Slider.h int main( int argc, char** argv ) { QApplication app( argc, argv ); Ui::SliderClass ui; QMainWindow window; ui.setupUi( &window );

UI Class

initialize with setupUi()

QMainWindow
window.showMaximized(); return app.exec(); }

67

Qt for N8 - Digia Plc

Single Inheritance
Easy to add custom functionality with custom slot functions UI Class becomes a member variable
#include "ui_Slider.h" class SliderApplication : public QMainWindow { Q_OBJECT public: SliderApplication(QWidget *parent = 0); ~SliderApplication(); public slots: void changeLcdColor(int value);

QMainWindow

SliderApplication UI Class

private: Ui::Slider ui; };

68

Qt for N8 - Digia Plc

Single Inheritance - Implementation


Slider::Slider(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); connect( ui.horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(changeLcdColor(int))); // Make sure the color value is correct in the beginning changeLcdColor( ui.lcdNumber->value() ); }

void Slider::changeLcdColor(int value) { QPalette pal = ui.lcdNumber->palette(); pal.setBrush( QPalette::WindowText, QBrush(QColor(value*2.55, value*2.55, value*2.55)) ); ui.lcdNumber->setPalette(pal); }

Dragging the slider now also changes the color of the LCD Number (from black to white)
69

Qt for N8 - Digia Plc

Summary
Own GUI often is an extended version of QMainWindow (or QDialog)
The main widget also acts as a parent for all other widgets/objects

Custom behaviour is added with custom slot functions that are connected to suitable signals Qt Designer can be used for quick UI layouting Qt Simulator can be used for quick mobile UI simulating Device deployment in Nokia Qt SDK pretty straightforward

70

Qt for N8 - Digia Plc

Hands-On!
Try it! Make it work!

71

Qt for N8 - Digia Plc

Animations & Effects


How to Make Little Something for Your QWidget UIs?

72

Introduction 1(2)
In Qt 4.6 a new Animation Framework was introduced The idea is to provide an easy and scalable way of creating animated and smooth GUIs
Hides the complexity of handling timers Provides a set of pre-defined easing curves, custom curves can be provided by the developer as needed

Works by modifying the properties of the QObjects being animated An animation is a linear interpolation of an objects property from the start value to the end value over a given time duration

73

Qt for N8 - Digia Plc

Introduction 2(2)
Can also be used easily together with the State Machine Framework to provide animated transitions between states Normally the animations have a finite duration
QTimeLine used as a timer behind the scenes Can be made to loop and run backwards

If loopCount is set to -1, the animation will run until explicitly stopped

74

Qt for N8 - Digia Plc

Main Classes

75

Qt for N8 - Digia Plc

Example Animating a Button


What do you think the example below does?

QPushButton button("Animated Button"); button.show(); QPropertyAnimation animation(&button, "geometry"); animation.setDuration(10000); animation.setStartValue(QRect(0, 0, 100, 30)); animation.setKeyValueAt(0.5, QRect(250, 250, 100, 30)); animation.setEndValue(QRect(0, 0, 100, 30)); animation.start();

Demo
76

Qt for N8 - Digia Plc

Animation Groups 1(2)


Classes QSequentialAnimationGroup and QParalleAnimationGroup can be used to run multiple animations in sequence or in parallel Their base class QAnimationGroup further derives from QAbstractAnimation
An animation group can be used wherever a normal animation could e.g. a group within a group Enables building very complex animation sequences

77

Qt for N8 - Digia Plc

Animation Groups 2(2)


QPropertyAnimation* animation1 = new QPropertyAnimation(...); QPropertyAnimation* animation2 = new QPropertyAnimation(...); QPropertyAnimation* animation3 = new QPropertyAnimation(...); QPropertyAnimation* animation4 = new QPropertyAnimation(...); QParallelAnimationGroup *parallel = new QParallelAnimationGroup(); parallel->addAnimation(animation2); parallel->addAnimation(animation3); QSequentialAnimationGroup* seq = new QSequentialAnimationGroup(); seq->addAnimation(animation1); seq->addAnimation(parallel); seq->addAnimation(animation4); seq->start();

78

Qt for N8 - Digia Plc

Easing Curves
The Animation FW provides multiple pre-made easing curves for your convenience
Represented by the class QEasingCurve Custom curves can made by the developer; see the class documentation for details

Typically used to control e.g. how the animation starts and/or finishes
QEasingCurve::OutBounce QEasingCurve::InOutQuad
QPropertyAnimation animation(&button, "geometry"); animation.setEasingCurve(QEasingCurve::OutBounce);

Take a look at the Easing Curves example in the Qt Demo tool


Demo
79

Qt for N8 - Digia Plc

Graphics Effects
Graphics effects provide an easy-to-use mechanism for adding effects on QGraphicsItems and QWidgets
QGraphicsItem::setGraphicsEffect(QGraphicsEffect*) QWidget::setGraphicsEffect(QGraphicsEffect*)

A group of standard effects are provided


See next slide for examples

Custom effects can be created by the developer


Simply a matter of imlementing a virtual draw() function See documentation in the base class QGraphicsEffect for details and guidelines

Effects operate by hooking into the rendering pipeline


I.e. operate between the source pixmap and the destination paint device to alter the result

80

Qt for N8 - Digia Plc

Standard Effects
QGraphicsBlurEffect QGraphicsOpacityEffect

Source

QGraphicsColorizeEffect

QGraphicsDropShadowEffect

81

Qt for N8 - Digia Plc

Applying and Animating an Effect


// Set up an effect QGraphicsOpacityEffect* effect = new QGraphicsOpacityEffect(this); effect->setOpacity(1.0); // 0.0 means fully transparent, 1.0 fully opaque // Apply to a graphics item QGraphicsPixmapItem *item = new QGraphicsPixmapItem(...); item->setGraphicsEffect(effect); // Animate the effect QPropertyAnimation* animation = new QPropertyAnimation(effect, opacity); animation->setDuration(1000); animation->setStartValue(1.0); animation->setEndValue(0.0); animation->start();

Demo
82

Qt for N8 - Digia Plc

Hands-On Animations!
Play around with
Qt Creator Nokia QT SDK Animations Framework Graphics Effects

See hands-on instructions for details

83

Qt for N8 - Digia Plc

Qt GraphicsView

84

Mobile Qt UI Offering

QGraphicsView

CUSTOM LAF

QWidgets

NATIVE LAF

85

Qt for N8 - Digia Plc

Custom UI w/ QGraphicsView
QGraphicsView is a QWidget, designed for showing custom 2D graphics inside: er e
tom Cus ph s gra go th

If the only widget (the window itself) is a QGraphicsView, the whole UI is then custom:

86

Qt for N8 - Digia Plc

Graphics View Architecture


Actually, inside a QGraphicsView, lies an architecture of its own
Super-duper optimized for doing everything fast and being flexible
QGraphicsView

Shows contents of one

QGraphicsScene

is a 2D container for

QGraphicsItem

87

Qt for N8 - Digia Plc

Working with GraphicsView


You code! Create a custom Item:
Derive from QGraphicsItem (or some other QGraphics* base class) Write code for painting operations with QPainter Write code for event handling Write code for animations etc.

88

Qt for N8 - Digia Plc

Qt Quick
Creating Outstanding UIs with Qt Quick

89

What is Qt Quick?
Qt User Interface Creation Kit
Combines concepts such as Declarative UI and QML

A high-level UI technology for easily creating attractive UIs


No C++ skills needed, knowledge of JavaScript helps quite a bit

Aimed at both UI designers and developers alike


Enables designers and developers to speak the same language! Both parties can be involved in iterative development simultaneously No need for separate Flash or PowerPoint UI prototypes

Officially launched in Qt 4.7


released 9/2010

OVI Store does not yet support Qt 4.7


DISCLAIMER: Qt Quick is for development purposes until Q1-Q2/2011

90

Qt for N8 - Digia Plc

Qt Quick More Concretely


A set of technologies including:
Declarative markup language: QML Language runtime integrated with Qt Qt Creator IDE support for the QML language Graphical design tool C++ API for integration with Qt applications, QtDeclarative

91

Qt for N8 - Digia Plc

QML
Qt Meta-Object Language A declarative, script-like language for defining the elements of a graphical UI
Actually an extension to ECMAScript (cf. JavaScript) Provides a mechanism to build an object tree of QML elements Enables interaction between QML elements and Qts QObject-based C++ objects

QML contains a set of QML elements and items


I.e. graphical and behavioral building blocks These are combined into QML documents to build more complex components and QML applications

Can be used to extend existing applications or to build completely new ones


QML itself is also fully extensible with C++!

92

Qt for N8 - Digia Plc

QtDeclarative
QtDeclarative is a new module in Qt
Enables running applications (partly) written in QML Also provides facilities for embedding QML content into Qt/C++ applications Implements the necessary QML <-> C++ bindings

Contains a tool called qmlviewer (qmlviewer.exe) for running standalone QML/JavaScript applications
I.e. allows viewing of .qml files without them being loaded into a proper Qt application Meant for development and testing purposes only! Provides a mechanism of providing dummy dynamic data for the QML code
The data are normally, of course, provided by Qt/C++ code when the final application version is run

93

Qt for N8 - Digia Plc

Development Tools
Qt Creator is the de facto tool for Qt development
Also for Qt Quick, of course!

Actually, to get started with Qt Quick, this is all you need


Preliminary support for Qt Quick in Qt Creator is already available Contains the qmlviewer (qml.exe) application built-in

To write proper Qt Quick UIs embedded in Qt/C++ applications, you will also need a Qt 4.7 SDK A WYSIWYG editor is coming, already a preview available

94

Qt for N8 - Digia Plc

Qt Quick
QML Intro

95

Introduction
As mentioned, QML is a declarative language for defining how:
An application looks like, and How it behaves

A QML UI is composed of a tree of elements with certain properties Prior knowledge of JavaScript (+ HTML and CSS) is an advantage when learning QML
Not strictly required, though

96

Qt for N8 - Digia Plc

QML Syntax, First Sneak Peek


/* woodenhead.qml starts here, with a multiline comment */ import Qt 4.7 Rectangle { width: 350 // Single line comment height: 2 * 100 color: "lightblue" }

Lets start off with a simple example: a light blue rectangular area on the screen Easy to read and understand?
Very JavaScriptish, right?

97

Qt for N8 - Digia Plc

Example Concepts, Elements


/* woodenhead.qml starts here, with a multiline comment */ import Qt 4.7 Rectangle { width: 350 // Single line comment height: 2 * 100 color: "lightblue" }

Declare the elements you want to use


One main element in the file, the root element

Each element has a body between { and } A set of default elements are included in the Qt module

98

Qt for N8 - Digia Plc

Standard QML Elements


A number of ready-made QML UI elements are provided for convenience
Item, Rectangle, Image, Text, MouseArea, WebView, ListView, Some of them can be used as containers (parent) for other elements (children) Referred to as QML items in the documentation
All elements meant for constructing the UI inherit the Item element

There are also elements that are used for describing the behavior of the application
State, PropertyAnimation, Transition, Timer, DateTimeFormatter, Connection, ... Referred to as QML declarative elements in the documentation

99

Qt for N8 - Digia Plc

Item Element
Has no visual appearance, but defines all the properties that are common to all UI elements
As mentioned, all UI elements inherit the Item element

Provides, for example:


X, y, z position Width and height Anchors (explained later) Opacity, rotation, scale Visibility (true/false) Parent and children Key event handling

100

Qt for N8 - Digia Plc

Example Concepts, Properties


/* woodenhead.qml starts here, with a multiline comment */ import Qt 4.7 Rectangle { width: 350 // Single line comment height: 2 * 100 color: "lightblue" }

Elements contain properties Each property is defined using its name and a value
name : value value can also be a piece of JavaScript

Multiple properties can be declared on the same line


Separate with semi-colons
Rectangle { width: 350; height: 2 * 100 color: "lightblue"
101

}
Qt for N8 - Digia Plc

Properties
QML supports properties of many types
Int, bool, real, color, string, list,

Properties are type-safe


I.e. assigning a string where and integer is expected is not allowed
Item { x: 10.5 // a 'real' property ... state: "details" // a 'string' property focus: true // a 'bool' property } Item { x: "hello" // illegal! }

102

Qt for N8 - Digia Plc

Example Summary
/* woodenhead.qml starts here, with a multiline comment */ import Qt 4.7 Rectangle { width: 350 // Single line comment height: 200 color: "lightblue" }

A Rectangle element with a body: { } three properties, width, height and color When executed in qml viever, will produce a light blue window of size 350x200

103

Qt for N8 - Digia Plc

Tree of Elements

104

Qt for N8 - Digia Plc

Example
Traffic Lights

105

Qt for N8 - Digia Plc

Summary
QML is a language for declaring UIs
Not imperative, line-by-line, code With JS can embed some logic to the QML code as well

One QML document defines one QML component that is a tree-like structure of Elements Elements consist of properties that can either have a fixed value or be bound into value of another property

106

Qt for N8 - Digia Plc

Qt Quick
User Interaction & Components

107

Creating own Components


QML Items are not ready user interaction components
More like drawing primitives

If you want to use a button, line edit or slider you will do it yourself
button = rectangle with a text and a mouse area accepting mouse clicks

New QML Components are very easy to do An official library of Mobile QML Components is also on its way

108

Qt for N8 - Digia Plc

Example, a Simple Button Component


// MyButton.qml import Qt 4.7 Rectangle { property alias text: textElement.text property alias textColor: textElement.color width: 100 height: 30 color: "grey" radius: 5 Text { id: textElement anchors.centerIn: parent text: "Button" color: "black" } MouseArea { anchors.fill: parent property color oldColor: "grey" onPressed: { oldColor = parent.color parent.color = "lightgrey" } onReleased: { parent.color = oldColor } } }

*click*

109

Qt for N8 - Digia Plc

Using the Button Component


We named the previous code file as MyButton.qml
=> We just created a component called MyButton
// main.qml import Qt 4.7 Rectangle { width: 150 height: 80 Column { spacing: 5 anchors.centerIn: parent MyButton { text: one" } MyButton { text: "two" color: "blue; textColor: white"} } }

110

Qt for N8 - Digia Plc

Hands-On: QML Sneak Peek!


Create a new Qt Quick project in Qt Creator Try creating elements, like Rectangles with different properties You can try using layout managers (Column, Row, Grid) and anchors Maybe a MouseArea could also be something worthwhile trying out!

111

Qt for N8 - Digia Plc

OK, Nice but Boring, What Else?


States
Every element can have a state machine

Animated transitions between states, with ease


Now were talking

Convenient View classes to use with existing Data Models


Those models can be/often are Qt/C++ Data Models

112

Qt for N8 - Digia Plc

Example, CD Cover View

113

Qt for N8 - Digia Plc

Qt Quick in Mobile Devices


.qml takes you nowhere You need compiled Qt/C++ .exe that loads the .qml file
QtDeclarative => Qt 4.7

Qt 4.7 available for Symbian devices


Development purposes

Ovi Store wont support Qt 4.7.0


4.7.1 should be supported, again

So, monetizing Qt Quick applications is soon to come, but now Qt 4.6.3 is the choice!

114

Qt for N8 - Digia Plc

How to Try Then, at Least?


Install Qt 4.7 SDK for your Symbian SDK (S^3, 5th Ed., N97, 3rd Ed.)
Install to device with the .sis that comes along

Compile project manually or with Nokia Qt SDK by selecting the correct Symbian SDK And thats it!

115

Qt for N8 - Digia Plc

GPU Accelerated Qt Quick in N8: Flowd Example


flowd.com

116

Qt for N8 - Digia Plc

Inside Flowd

QML UI QtMobility APIs QtDeclarative

Qt/C++ Engine

117

Qt for N8 - Digia Plc

Experiences with Serious Qt Quick Development


Really Quick to develop
Fast prototyping Also, great fun

BUT, Lots of things missing: No UI FW


View switching manual loading/unloading of resources portrait/landscape

No components (yet)
no styling

118

Qt for N8 - Digia Plc

Qt Mobility Bindings
Qt Mobility 1.1 (now in beta) includes QML Bindings for all classes You can access mobility APIs functionality directly from QML RotationSensor { onReadingChanged: { } }

119

Qt for N8 - Digia Plc

Mobile Qt UI Offering, Prospects


Renewed NATIVE LAF

Qt Quick Components (Symbian)

Qt Quick Cmpnts (MeeGo)

QGraphicsView

Qt Quick

QtWebkit

CUSTOM LAF

QWidgets

NATIVE LAF

120

Qt for N8 - Digia Plc

Qt Quick Components
The abstraction level for QML programming will also rise Component libraries that allow creation of Qt Quick programs from a set of ready UI components
Components imitate existing LAF

In Qt Labs phase at the moment

121

Qt for N8 - Digia Plc

Porting Mobile Applications to Qt

122

Contents
Different Application Approaches in Nokia Devices Porting from iPhone or Android to Qt, no code re-use
Mapping concepts

Porting from native Symbian/maemo to Qt, how to re-use platform code


Porting Alternatives:
Hybrid UI Engine Wrapping

123

Qt for N8 - Digia Plc

Different Application Approaches in Nokia Devices


WEB

Qt C++

WEB

Qt C++ 1. Qt 2. QtWebkit 3. WRT

A variety of technologies for selecting the most suitable approach exists

124

Qt for N8 - Digia Plc

Qt Applications
Qt C++

Qt Quick UI Qt C++, UI with QWidgets C++, UI with Graphics View C++ Native LAF Custom LAF Custom LAF with

easy-to-develop More native applications script-like syntax multiple UI approaches Extensive engine support through Qt and Qt Mobility APIs

125

Qt for N8 - Digia Plc

QtWebkit

WEB

Qt C++

Possibility to embed dynamic contents to Qt C++ program E.g. create the whole UI with Web technologies and show it in QWebView Widget Collaborate between JavaScript and C++ Re-use existing web documents

126

Qt for N8 - Digia Plc

More Concretely, from iPhone/Android to Qt?


iPhone (Objective-C) and Android applications only work on their native platforms--which are not Qt-compatibile Reusing parts of applications is basically not possible when porting to Qt
Porting requires complete code level re-implementation with Qt

Lets look shortly into few fundamental characteristics of both platforms


Comparison to Qt Conceptual mapping of native elements to Qt

127

Qt for N8 - Digia Plc

iPhone Overview
Applications in iPhone are written using the Objective-C programming language Development of Objective-c applications requires the use of Apple environment Tools in use
Objective-C: XCode Qt/Symbian: Qt Creator, Carbide.c++

128

Qt for N8 - Digia Plc

Objective-C Application Framework


Applications for iPhone are written using Objective-C and using the Cocoa framework
Objective-C is an own language, actually an extension of ANSI C

The Cocoa framework consists of libraries, APIs and runtimes that form the development layer for all of Mac OS X
Applications automatically inherit the same Mac OS X LooknFeel

Objective-C application architecture

129

Qt for N8 - Digia Plc

iPhone Application Features


UIKit is iPhones runtime UI framework which provides a set of UI components but also access to device services (like camera and accelerometer)
Set of UI components is rather similar to Qt Homogenous LAF

Only one foreground iPhone application can be executed at a time (excluding iPhone 4)
When user selects application icon from menu, new process launches Pressing home screen button closes the application process Applications try to imitate background execution by state saving

iPhone supports multitouch events by nature


UIEvent consists of UITouch objects (one for each finger) Qt 4.6 introduced a new Gesture Framework to provide fluent touch UI support

130

Qt for N8 - Digia Plc

Android Platform Overview


Android is an open and free platform for mobile phones Based on Linux-kernel, but Google says it is not a Linux OS Own windowing system Not supporting full set of standard Linux libraries, like GNU C Library
Reuse of existing Linux apps or libraries difficult

131

Qt for N8 - Digia Plc

Android Applications Overview


Applications developed with Java using own Dalvik VM
Device services, like touchscreen and storage accessed through Google services API

Android does not use standard Java APIs, such as J2SE or J2ME
Not compatible with Java apps written for other platforms

Android apps do not provide one entry point (like main function) but a set of essential components
Activities, services, broadcast receivers and content providers Application process is started when any part of it is needed, and instantiate Java objects for that part

132

Qt for N8 - Digia Plc

Comparing Android and Qt UI Concepts


Activity QWidget that is a window (main widget) Qt Widgets
Activity
contains

Android Views
View structure

Different set of widgets Qt Parent/child relationship

Main widget (QWidget)


contains

Views

Dialog

QDialog

Child widgets (QWidget)

Similar Layout managers Event handling:


dispatch() onEvent() Looper::loop() QObject::event() QObject::Event() QApplication::exec()

133

Qt for N8 - Digia Plc

Porting Different Types of Mobile Apps to Qt


Applications based on web technologies or applications with embedded web content
WRT QtWebkit Re-use of graphics, extend engine with C++
WEB Qt C++ WEB

Applications with standard device UI


Qt C++ with standard QWidgets

Qt C++, UI with QWidgets

Games without heavy graphics-rendering requirements


Qt Quick

Qt Quick UI

C++
C++, UI with Graphics View

Games with heavy, real-time graphics and/or 3D


Qt with Graphics View

134

Qt for N8 - Digia Plc

Porting Summary
iPhone & Android
No code re-use Web content/graphics can be re-used Different alternatives for re-implementation for different purposes (Qt, Qt w/ Graphics View, Qt Quick, QtWebkit, WRT)

Symbian & Maemo


Code re-use possible UI should be ported and Engine should be wrapped

135

Qt for N8 - Digia Plc

Qt Mobility APIs

136

Background
Qt originally designed for desktop OSs
Originally no APIs for mobile device related features

QtMobility APIs will fill this gap


Cross-platform solution, and not only for mobile OSs!

Latest version 1.1

137

Qt for N8 - Digia Plc

Mobility API Roadmap


1.0.2
Bearer Management
(to QtNetwork in 4.7)

1.1

Later?

Service Framework

Organizer

Augmented Reality

Publish&Subscribe

Versit

Document Gallery

Face Recognition

Messaging

Sensors

Feedback

Local Connectivity (BT, NFC)

Contacts

Multimedia Telephony Events Camera


removed!

System Information

Location Landmarks, Maps, Navigation

138

Qt for N8 - Digia Plc

Status at 1.1

139

Qt for N8 - Digia Plc

Installation
Comes with Nokia Qt SDK Install the .sis for the device
Also comes with Nokia Qt SDK

140

Qt for N8 - Digia Plc

First Intro to Mobility APIs


#include <QtGui/QApplication> #include <QtGui/QLabel> #include <QSystemInfo> QTM_USE_NAMESPACE; int main( int argc, char *argv[] ) { QApplication app( argc, argv ); QSystemInfo s; QLabel *label = new QLabel( "Current language is "+ s.currentLanguage() + " and you're using Qt " + s.version(QSystemInfo::QtCore) ); label->show(); return app.exec(); }

Were using class QSystemInfo from the System Information API

141

Qt for N8 - Digia Plc

First Intro to Mobility APIs


Equivivalent to using namespace QtMobility;
#include <QtGui/QApplication> #include <QtGui/QLabel> #include <QSystemInfo> QTM_USE_NAMESPACE;

int main( int argc, char *argv[] ) { QApplication app( argc, argv ); QSystemInfo s; QLabel *label = new QLabel( "Current language is "+ s.currentLanguage() + " and you're using Qt " + s.version(QSystemInfo::QtCore) ); label->show(); return app.exec(); }

All classes within Mobility APIs are placed inside namespace QtMobility. You can raise the whole namespace or either use syntax QtMobility::<ClassName>, like QtMobility::QSystemInfo

142

Qt for N8 - Digia Plc

First Intro to Mobility APIs


#include <QtGui/QApplication> #include <QtGui/QLabel> #include <QSystemInfo> QTM_USE_NAMESPACE;

QSystemInfo provides access to various general information from the system, like here the language and version of Qt Libs

int main( int argc, char *argv[] ) { QApplication app( argc, argv ); QSystemInfo s; QLabel *label = new QLabel( "Current language is "+ s.currentLanguage() + " and you're using Qt " + s.version(QSystemInfo::QtCore) ); label->show(); return app.exec(); }

143

Qt for N8 - Digia Plc

Mobilizing the .pro file


TEMPLATE = app TARGET = DEPENDPATH += . INCLUDEPATH += . CONFIG += mobility MOBILITY += systeminfo # Input SOURCES += main.cpp

144

Qt for N8 - Digia Plc

Compiling
Nokia Qt SDK

Windows (with mingw32-make)


qmake mingw32-make release

Symbian
qmake make release-gcce To create/install the .sis createpackage i hw_template.pkg release-gcce

145

Qt for N8 - Digia Plc

System Information API Classes


QSystemDeviceInfo Device information (battery, power state, input method type, IMEI, manufacturer, profile status etc.) Display information (color depth, brightness)

QSystemDisplayInfo

QSystemInfo

Various general information (like in the previous example)

QSystemNetworkInfo

Network information (network name, signal strength, network mode, etc.)

QSystemScreenSaver

Access to screen saver (inhibiting it)

QSystemStorageInfo

Memory and disk information (drive types, free space)

146

Qt for N8 - Digia Plc

QSystemDeviceInfo Example

Small application to show the current profile, battery level and power status
Profile status naturally not available in Windows

Demo
147

Qt for N8 - Digia Plc

Using QSystemDeviceInfo Example (1/4) Window Class Header


class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); public slots: void changePowerState(QSystemDeviceInfo::PowerState state ); void changeProfileInfo( QSystemDeviceInfo::Profile profile ); private: Ui::MainWindow *ui; QtMobility::QSystemDeviceInfo* m_device; };

148

Qt for N8 - Digia Plc

Using QSystemDeviceInfo Example (2/4) Constructor


MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_device( new QSystemDeviceInfo(this) ) { ui->setupUi(this); // batteryBar is a QProgressBar ui->batteryBar->setValue(m_device->batteryLevel()); changePowerState(m_device->currentPowerState()); // Self-created slot function changeProfileInfo(m_device->currentProfile()); // Self-created slot function connect( m_device, SIGNAL(batteryLevelChanged(int)), ui->batteryBar, SLOT(setValue(int)) ); connect( m_device, SIGNAL(powerStateChanged(QSystemDeviceInfo::PowerState)), this, SLOT(changePowerState(QSystemDeviceInfo::PowerState))); connect( m_device, SIGNAL(currentProfileChanged(QSystemDeviceInfo::Profile)), this, SLOT(changeProfileInfo(QSystemDeviceInfo::Profile))); }

149

Qt for N8 - Digia Plc

Using QSystemDeviceInfo (3/4) Examining the Power State


void MainWindow::changePowerState( QSystemDeviceInfo::PowerState state ) { switch( state ) { case QSystemDeviceInfo::BatteryPower: ui->stateLabel->setText( "Battery power"); break; case QSystemDeviceInfo::WallPower: ui->stateLabel->setText( "Wall power" ); break; case QSystemDeviceInfo::WallPowerChargingBattery: ui->stateLabel->setText( "Wall power and charging" ); break; default: ui->stateLabel->clear(); } }

150

Qt for N8 - Digia Plc

Using QSystemDeviceInfo (4/4) Examining the Profile Change


void MainWindow::changeProfileInfo( QSystemDeviceInfo::Profile profile ) { switch( profile ) { case QSystemDeviceInfo::SilentProfile: ui->profileLabel->setText( "Silent" ); break; case QSystemDeviceInfo::NormalProfile: ui->profileLabel->setText( "Normal" ); break; case QSystemDeviceInfo::LoudProfile: ui->profileLabel->setText( "Loud!" ); break; case QSystemDeviceInfo::OfflineProfile: ui->profileLabel->setText( "Offline" ); break; case QSystemDeviceInfo::CustomProfile: ui->profileLabel->setText( "Custom" ); break; default: // VibProfile or PowersaveProfile are not handled separately ui->profileLabel->clear(); } }

151

Qt for N8 - Digia Plc

Service Framework API


Defines a unified way of finding, implementing and accessing services across multiple platforms.
Client-server (service provider) abstraction

Functionality can be shared between applications Developer has device independent methods for finding/using/implementing services

Picture: Qt Mobility Whitepaper, http://qt.nokia.com/files/pdf/qt-mobilitywhitepaper-1.0.0

152

Qt for N8 - Digia Plc

Publish & Subscribe


The Publish and Subscribe API enables applications to read item values, navigate through and subscribe to change notifications Values are represented by a QValueSpace
Hierarchical tree of which each node or leaf can optionally contain a QVariant value
QVariant is a union data type Nodes act as Paths which can be subscribed to
Serialized QValueSpace example: /Device/Buttons = 3 /Device/Buttons/1/Name = /Device/Buttons/1/Usable /Device/Buttons/2/Name = /Device/Buttons/2/Usable /Device/Buttons/3/Name = /Device/Buttons/3/Usable

Menu = true Select = false Back = true

Access with QValueSpaceSubscriber


Read values, receive change notifications, navigate through QValueSpace

New values are added with QValueSpacePublisher

153

Qt for N8 - Digia Plc

Sensors API
The API supports sensors that poll for their data and sensors that push data to the app as it arrives
Application Code QSensor QSensorBackend

QSensorReading

Device Plugin

QSensor (and its subclasses) provide application with access to data input from a sensor
Direct subclass instantiation QSensorReading subclasses represent single readings from a single sensor

QSensorBackend can be used to make sensors available through the same API, by creating plugins

154

Qt for N8 - Digia Plc

Existing QSensor Subclasses


QAccelerometer QAmbientLightSensor QCompass QMagnetometer QOrientationSensor QPromiximitySensor QRotatienSensor QTapSensor Linear acceleration along the X, Y and Z axes Ambient light sensor Compass Magnetometer Orientation Proximity (if something is close) Rotation Tap sensor (registers tap and double tap events in 6 directions)

155

Qt for N8 - Digia Plc

Using Sensors, Demos

Proximity Sensor Test

Horizonize with Orientation sensor

156

Qt for N8 - Digia Plc

Now you, Adaptive Flashlight Hands-On!


See exercise book for instructions!

157

Qt for N8 - Digia Plc

Messaging API
Access to messaging services
Search and sort Create and modify Send and retrieve Launch preferred message client

A unified interface for manipulation and storage of SMS, MMS, Email and XMPP messages is provided

158

Qt for N8 - Digia Plc

Key Classes for Messaging


Composition and manipulation of messages:
QMessage QMessageAddress

Accessing message accounts


QMessageAccount QMessageFolder

Sorting and filtering


QMessageStore QMessageFilter

Accessing message services


QMessageService

159

Qt for N8 - Digia Plc

Creating a Message
// The developer creates a QMessage object and then sets the necessary message details. First set the message type, the default account for messages of the specified type will be used for sending : QMessage message; message.setType(QMessageAddress::Email); // Now a recipient is set : QString recipient(user@example.com); message.setTo(QMessageAddress(QMessageAddress::Email, recipient)); // For email a subject and a body are set, and any relevant attachments added : message.setSubject(Example subject); message.setBody(Example body text); QStringList attachmentPaths; attachmentPaths << images/landscape.png; message.appendAttachments(attachmentPaths);

160

Qt for N8 - Digia Plc

Sending the Message


// The message is ready to send. Next, create a service object and call the send() function QMessageService *m_service = new QMessageService(); if (!m_service->send(message)) { QMessageBox::warning(0, tr(Failed), tr(Unable to send message)); }

Opening the Default Composer


// Will open the default composer for messages of this type and with the existing message as the initial situation QMessageService *m_service = new QMessageService(); m_service->compose(message)

161

Qt for N8 - Digia Plc

Location API
This API provides an easy to use interface that encapsulates basic geographical information obtained from satellite or other sources about the user
QGeoPositionInfo class contains information gathered on a global position, direction and velocity at a particular point in time

Multiple methods for receiving location data


GPS Cell ID Anything derived from QGeoPositionInfoSource

Also support for direct access to any NMEA data


Common text-based protocol for navigational data

162

Qt for N8 - Digia Plc

Monitoring Position Data


Default position source may be available on some platforms
QGeoPositionInfoSource::createDefaultSource()

QGeoPositionInfoSource is simple to use


requestUpdate() startUpdates() (and setUpdateInterval() ) positionUpdated( QGeoPositionInfo ) [signal] is emitted after each interval stopUpdates()

163

Qt for N8 - Digia Plc

Simple Client Receiving Location Data


class MyClass : public QObject { Q_OBJECT public: MyClass(QObject *parent = 0) : QObject(parent) { QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this); if (source) { connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo))); source->startUpdates(); } } private slots: void positionUpdated(const QGeoPositionInfo &info) { qDebug() << "Position updated:" << info; } };

164

Qt for N8 - Digia Plc

Demo! - Locationer
Get your location and send to your friend via SMS!

165

Qt for N8 - Digia Plc

Contacts API
The Contacts API allows developers to manage contact data in a platform independent way.
A contact is the digital representation of a person, group or entity A contact consists of a set of contact details with own semantics of usage and storage with different context info (like separate phone number for work and home)

QContactManager unifies one or more platform-specific contact backends

166

Qt for N8 - Digia Plc

Main Contact Classes


QContact Addressbook contact

QContactDetail

Single detail of a QContact

QContactManager

Access to contacts stored in particular backend Used to select contacts through QContactManager Interface for performing actions to contacts (like Send email or Dial)

QContactFilter

QContactAction

167

Qt for N8 - Digia Plc

Versit API
Functionality for reading and writing Versit documents such as vCards
QVersitDocument QVersitReader QVersitWriter

Utilities to import/export QContacts from/to Versit documents


QVersitContactImporter QVersitContactExporter

168

Qt for N8 - Digia Plc

Bearer Management API


Now part of Qt 4.7 QtNetwork! Manages the connectivity state to the network
Allows user to start or stop network interfaces Is device online and how many available interfaces there are

Allows comparison and prioritization of the access and use of grouped access points When using Bearer Management the developer does not need to worry about locating the best connection
User selects best Transparent selection

Automatic roaming between cellular and WLAN networks

169

Qt for N8 - Digia Plc

Classes for Bearer Management


QNetworkConfiguration Abstraction of one or more access point configurations.

QNetworkConfigurationManager

Manages the network configurations provided by the system

QNetworkSession

Control over the system's access points and enables session management for cases when multiple clients access the same access point

170

Qt for N8 - Digia Plc

Small Example on Bearer Management

Application lists available network configurations and shows small information on the selected one
UI consists only of a QListView and a QTextBrowser QListView uses QStringListModel (which has the names of the configurations)

For a more complex example, see Bearer Monitor example of the Mobility APIs

Demo
171

Qt for N8 - Digia Plc

Multimedia APIs
Play audio & video of various formats Record audio Playing and managing of an FM radio With QtMultimedia, will eventually replace Phonon API Access of multimedia services with minimal code and maximal flexibility

172

Qt for N8 - Digia Plc

Overview on Multimedia API (Main Classes Only)

Included in 1.1.0

173

Qt for N8 - Digia Plc

Mobility API Roadmap


1.0.2
Bearer Management
(to QtNetwork in 4.7)

1.1

Later?

Service Framework

Organizer

Augmented Reality

Publish&Subscribe

Versit

Document Gallery

Face Recognition

Messaging

Sensors

Feedback

Local Connectivity (BT, NFC)

Contacts

Multimedia Telephony Events Camera


removed!

System Information

Location Landmarks, Maps, Navigation

174

Qt for N8 - Digia Plc

Summary

175

Thank You!

www.digia.com

176

Qt for N8 - Digia Plc

Você também pode gostar