Comprehensive presentation about Qt with special focus on Symbian. Close to a training material so if you wanna know what Qt is, have a look at the ~150 slides.
Held in www.see2009.org/ 27.10.2009
6. 2010 : Back to the track –
The Cross Platform Promise
Increase Total Commit to
Addressable Market Open Source
Combine the Best of Lower Entry Barriers
Both Worlds for Developers
6
6
8. Why Qt?
What is Qt about?
• QuickTime player? Programming language? A platform? Yet another runtime?
• A new Japanese car model?
Qt is Cross-platform application framework
• Differentiated user experience across hardware platforms
• Hybrid development: convergence of web and native applications
• Cross-platform software across desktops and mobile devices. Qt supports major
desktop OSs already and will extend it’s reach to Nokia platforms.
• Qt is not a runtime – no perf issues or sandbox restrictions. You can stand out with your
native development skills to fulfill the use cases offered by Qt.
• Qt Mobility APIs will bring in the easy to use APIs for mobile use cases.
Shorter time to market
• Productive APIs and comprehensive documentation with great examples
• Delivering functionality faster and maximizing efficiency by placing focus on innovation
• All the great tools offered free of charge - commercial services available as well
8
8
9. Today : Qt is used already used
everywhere!
From embedded devices By companies
to desktop applications from many industries
9
10. Qt: a cross-platform application and
UI development framework
http://qt.nokia.com
10
11. Nokia + Ovi Developer Story | 11
Simplified offering | Based on Qt
The future offering will be based on Qt, the development tool globally used to
build desktop apps – you may already know it.
With the simplified toolchain
you can tackle f.ex Maemo
and Symbian based devices
Develop on PC, Mac or Linux
11
12. Qt and Web is the way to go
Web
Web Runtime developers
For native
Qt UI Extensions
Developers
UI 85% of use
cases **
Qt
Engine
Mobile
Qt Mobility APIs
Features
Low level Native Native Native 15% of use
Native access
APIs APIs APIs cases **
Desktop
Symbian Linux
OSs
S60 on Symbian maemo
Platform Platform
* Internal SAPIs, not for 3rd parties
** Not based in any realiable statistics ;)
12
13. Qt on Symbian path
UI
Qt Qt
Qt
Qt
Engine
with
Mobility
Qt Mobility Qt Mobility
APIs rel 1 APIs
Mobile Rel 2
Features Symbian
C++
Symbian Symbian
Low level C++ Symbian
C++
Native access C++
Desktop
OSs
Nokia Symbian Symbian
S60 on Symbian S60 on Symbian
Platform Platform
13 2011
14. Qt Development Chain - maemo & Symbian
Distribution Ovi Store
Certification Symbian signed None - atleast yet…
IDEs •Qt Creator •Qt Creator
•Carbide
Common
offering
•Mobility APIS •Mobility APIs
SDKs
Qt for Symbian platform Qt for maemo platform
&
Plugins Symbian SDKs Maemo SDKs
Symbian Maemo
14
15. Maemo - Why should I care?
• Coming from desktop?
• The importance of mobile clients is widely recognized already – not gonna sell it here…
• With Qt and Mobility APIs you can easily extend your application to cover smartphone features
and utilize f.ex location, contacts, messaging etc.
• With maemo and Symbian you can reach more than 100 million devices with your Qt
application – already with Qt 4.6!
• Maemo is and will be very important for Nokia
– get a head start to maemo which we believe will be one of the most interesting platforms!
• With Ovi store you have a ready channel to sell your application to hundreds of millions
of users
15
16. Nov 2009 : get your Qt app running
on more than
+ 130 000 000 smartphones!
- Not to mention that Qt runs on all major
desktop OSs as well
16
19. What is Qt? (1/2)
• Qt (”cute”) is often referred to as a cross-platform GUI framework
• Cross-platform GUI has been the driving force
• Initially other modules did not even exist
• However, nowadays Qt is much more than a plain GUI FW
• Qt is a cross-platform C++ application development framework
• Set of cross-platform APIs and
• C++ class library
• Development tools
• Qt was originally designed for efficient creation of platform-independent desktop GUI
programs
• Developed by a Norwegian company called Trolltech, which has been part of Nokia since
2008
• Latest version is 4.6 (beta)
• Qt provides native look-and-feel in all platforms
• Implemented by relying on platform-specific APIs
• Platform specialities isolated
19
http://qt.nokia.com
20. Qt is supported in wide range of platforms
• Qt is currently ported to
• Desktops: Windows, Linux (X11), Mac
• Mobile: Windows CE, S60, and embedded Linux, e.g. Maemo
One and unified Cross-Platform API
Qt/Embedded
Qt/X11 Qt/Win Qt/Mac Qt/WinCE Qt/S60
Linux
20
21. Qt Application Framework
• Qt includes an intuitive C++ class library with a rich set of application build blocks
• Qt goes beyond C++ in the areas of inter-object communication and flexibility for advanced
GUI development.
• Combining the speed of C++ with the flexibility of the Qt Object Model Qt provides both
runtime efficiency and a high level of flexibility for GUI programming.
• Qt goes beyond C++ to add the following features:
• A very powerful mechanism for seamless object communication called signals and slots
• Queryable and designable object properties
• Powerful events and event filters
• Contextual string translation for internationalization
• Sophisticated interval driven timers that make it possible to elegantly integrate many tasks in
an event-driven GUI
• Hierarchical and queryable object trees that organize object ownership in a natural way
• Guarded pointers (QPointer) that are automatically set to 0 when the referenced object is
destroyed
• A dynamic cast that works across library boundaries
21
24. Qt for Symbian - Total Offering
• http://qt.nokia.com - main place for Qt related development material
• Qt for Symbian port – Qt 4.6 ported to S60 3rd Edition FP1 and FP2, 5th edition and also
coming S60 platform editions.
• Carbide.c++ 2.0.2 onwards supporting Qt development on Symbian.
• Note : Qt creator will also support Symbian development
• Fully integrated form editor (Qt Designer)
• Wizards for creating new Qt projects and classes
• Integrated .pro file editor
• Automated build setup for moc, uic, and rcc
• http://www.forum.nokia.com/Resources_and_Information/Tools/IDEs/Carbide.c++/
• Mobility APIs
• http://labs.qt.nokia.com/page/Projects/QtMobility
• And Their successor : Qt for S60 Mobile Extension
• High abstraction level APIs making it possible to use most important services without using native
Symbian C++
• Note : for a long time Qt developer will need Symbian APIs in specific use cases
• Documents, examples, discussion board, wiki, Technical support, consultancy etc
24
25. Qt for Symbian Developer’s
Library
• After installing the ’Qt for Symbian Developer’s
Library’ Carbide plugin you will see it in Carbide help
(select Help->Help Contents from Carbide menu bar)
• Note that the Qt Development User Guide that is
‘built-in’ with Carbide 2.0 is a separate library
• The developers library contains the following
sections
• Legal notice & Release notes
• Introduction to Qt
• Introduction to S60
• Installation guide
• Using Carbide.c++
• Qt for S60 guide
• Qt-related books and URLs
• Example ‘Qt for S60’ applications
25
http://library.forum.nokia.com/
26. ”smart installer” - Qt installer for Symbian
The opportunity The problem The solution
A Smart Installer tool that
+130M Symbian devices Qt libraries need to be
checks whether needed Qt
could run cross-platform Qt post installed – most
version is available on the
applications already during consumers might not
device – and if not, it will
this year bother
handle the installation
Details
•Nokia is working on a tool called Smart Installer for Symbian devices
•The expected availability is 1Q 2010
•A piece of code is to be packaged together with the Qt application targeted for Symbian devices (when
creating the .sis file)
•The Smart Installer will download OTA the needed Qt version to the handset if it is not already present
26
28. Tools – configure
• configure is a tool for configuring Qt itself for the current platform
• Compiles qmake
• Executed only during Qt installation
• Unless ready binaries are used (recommended)
• Configure is platform independent – not Symbian specific
qmake
Qt Source Code configure
Qt for
specific platform
28
29. Building Qt Applications
1. qmake –project
• Creates a Qt project file (.pro). This can also be created manually.
2. qmake
• Uses the .pro file as input and produces platform-specific Makefile(s)
• Generates make rules to invoke moc for project header files containing
Q_OBJECT – as explained later
3. make
• On Symbian make debug-winscw or make release-gcce
• Compiles the program for the current platform
• Executes also moc, uic and rcc
qmake Project Platform Application
qmake specific make
-project information Binary
file (.pro/.pri) Makefiles
29
31. What is Qt Creator?
Lightweight, cross-platform IDE for Qt
• Advanced C++ code editor
• Integrated, context sensitive help system
• Integrated visual debugger (based on gdb)
• Integrated source code management
• Project and build management tools
• Integrated Qt development tools
31
32. What does Qt Creator provide?
Lighting fast code Tailored to the needs Powerful C++
navigation tools of Qt cross-platform code editor
developers
32
33. Tailored to the needs of Qt
cross-platform developers
Challenge
• Qt is cross-platform, but IDEs/dev. environments are not
• Can be difficult to get up with a new framework
Solution
• True cross-platform development environment for Qt
• Integrated Qt-specific features (i.e. Signals & Slots)
• Debugger aware of Qt class structures
• New developers get productive sooner
Visualizing Qt class structures in Debug mode.
33
34. Powerful C++ code editor
Challenge
• Writing elegant, correct code can be time consuming
• Finding help often demands context switching
Solution
• Syntax highlighting and automatic code completion
• Static code checking as you type
• Context sensitive help
• Code folding Code completion.
• Parenthesis matching and parenthesis selection modes
• Advanced editing capabilities like block selection
Context-sensitive help.
34
35. Available as part of complete SDK
Qt SDK
Qt Development Tools
Qt Libraries Qt Designer Qt Assistant
Licensing Options:
GUI Layout & Help file/documentation
Forms Tool browser
Commercial
LGPL
Qt Linguist qmake
Translation/I18n Tool Cross-platform build tool
35
37. Qt Modules
• Cross-platform Qt consists of 12 modules
• A little bit less than 700 API classes, all modules depend on QtCore
• Additionally 3 platform specific modules: QAxContainer, QAxServer, QtDBus
• Build Tools
• Configure, Qmake, Moc, Uic and Rcc
• Development Tools
• Qt Creator, Qt Designer, Qt Assistant, Qt Linguist, Carbide
• Enables pure Qt applications, but
• Possibility to use platform APIs
• Possibility to embed native
elements, including UI widgets
QtOpenGl QtSvg QtWebKit QtXmlPatterns Qt3Support
QtGui QtSql QtXml QtNetwork QtScript Phonon
QtCore
37
38. Qt for Symbian Platform - releases
FINAL
Beta based on
QtXmlPatterns QtOpenGL
Qt 4.6 October
Tower July-09 QtSql Phonon QtWebkit
based on 4.5
Garden P3-09 QtXml QtScript QtSvg
based on 4.5
Pyramid P10 QtGUI *) QtCore QtNetwork QtTest Q3Support
based on 4.4
http://pepper.troll.no/s60prereleases/
38
40. Qt – Modules (Core) QtOpenGl QtSvg QtWebKit QtXmlPatterns Qt3Support
• Classes and methods for basic non-GUI functionality
QtGui QtSql QtXml QtNetwork QtScript Phonon
• Basic Type (Char, Date, Time, String) QtCore
• File system access, Date and time handling
• String handling, List and array handling
• Threads and processes, Shared resources
• Libraries and Plugins, Timers
• Classes and methods for basic graphical elements
• Point, Rectangle
• Heart of the Qt object model, QObject
• More information about Qt object model later on
• QtCore do not depend on underlying window system
40
41. QObject Class Role
• Heart of Qt's object model
• Base class for all object classes
• Provides object trees and object ownership
• QObject's responsibility is to provide a central location for the most important
concepts in Qt
• Has three major responsibilities
• Memory Management
• Introspection
• Event handling
41
42. Parent/Child Relationship
• Each QObject instance may take a parent (argument for constructor)
• Child informs its parent about its existence, upon which the parent
adds it to its own list of children
• If a widget object does not have a parent, it is a window
• The parent does the following for its children:
• Deletes them, when it is self deleted –
• But, of course, is not able to set your own direct pointers to those children to
NULL (if not using quarded pointers!
• Hides and shows children, when hidden/shown itself
• Enables and disables children when enabled or disabled itself
• Note that a child may be explicitly hidden, although the parent is
shown
42
43. Creating Objects
• Objects inheriting from QObject are allocated on the heap using new
• If a parent object is assigned, it takes ownership of the newly created
object – and eventually calls delete
• QLabel *label = new QLabel(”Some Text”, parent);
• Objects not inheriting QObject are allocated on the stack, not the heap
• QStringList list;
• QColor color;
• Exceptions
• QFile and QApplication (inheriting QObject) are usually allocated on the
stack
• Modal dialogs are often allocated on the stack, too
43
44. Memory Management
• The ownership of all child QObjects is transferred to the parent
• Automatic deletion by the parent
• Allocated from the heap with new
• Manual deletion won’t however cause double deletion because the child informs its
parent of the deletion
• All QObjects without a parent must be deleted manually
• Stack allocation is a good option to avoid problems
• Occasionally it may seem like Qt would hold some sort of automatic garbage
collection but this is not true!
• Always pay attention to ownerships and responsibilities!
44
45. Meta-Object System
• Meta-object system extends C++ with dynamic features – similar to those in
Java, for example
• Dynamic features include
• Mechanism to access any functions in the class
• Also private ones
• Used by signals and slots
• Class information
• Type without RTTI (Run-Time Type Information)
• Information about base classes
• Translate strings for internationalization
• Dynamic properties
45
46. Signals and Slots
• Observer pattern
• Type-safe callbacks
• More secure than callbacks, more flexible than virtual methods
• Many-to-many relationship
• Loose coupling between signals and slots
• Implemented in QObject
46
47. 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
• An asynchronous service handler is finished
• Value of QSlider is changed
• Signals are member functions that are automatically implemented in the meta-object
• Only the function declaration is provided by the developer
• Signal is sent, or emitted, using the keyword emit
• emit clicked();
• emit someSignal(7, “Hello”); //passing data in a connection
47
48. Slots
• A slot is a function that is to be executed when a signal has been emitted.
• (When QPushButton is pressed), close QDialog
• (When service is ready), ask for the value and store it
• (When QSLider value is changed), show a new value in QLCDNumber
• A Slot function is a normal member function implemented by the developer
48
49. 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);
public slots:
// Slots are implemented as normal member functions
void newSlot(int i, QString s);
}
49
52. Event Handling in Brief
• In Qt, events are objects that are delivered to event handling functions
• Base class QEvent, subclasses like QMouseEvent, QKeyEvent, QTimerEvent
• When an event occurs, Qt creates the event object and delivers the event to the
particular QObject
=> QObject::event( QEvent& e )
• Does not handle the event, redelivers to a corresponding virtual event handler
• Own virtual protected functions for different events
52
53. You Want to Have Your Widget to...
• Respond to key presses, implement:
void keyPressEvent(QKeyEvent&)
• Use timer, implement:
void timerEvent(QTimerEvent&)
QObject
• Respond to mouse presses, implement:
event
void mousePressEvent(QMouseEvent&) (QEvent&)
• React to layout changes, implement:
void resizeEvent(QResizeEvent&)
void moveEvent(QMoveEvent&) MySubClass
keyPressEvent
• Etc. (QKeyEvent&)
• Quite straightforward from the developer’s point
of view!
53
54. Timer Events
int QObject::startTimer ( int interval )
• Starts the timer, which will continuously send timer events at specified intervals
(ms)
• Returns the timer id
• Stops when QObject::killTimer(id) is called
• Class QTimer can also be used
• Both repetitive and single-shot timer events
• Emits signal timeout() when the timer expires
• A zero-millisecond QTimer can be used to perform low-priority background tasks –
compare to CIdle in S60/Symbian
54
55. Timers
• QTimer is a class for executing functions at a later time. You create an instance of a QTimer and connect the
signal timeout() to a slot containing the code you want to be executed.
• Call setSingleShot() for a single-shot timer.
• Finally, call start(int msec) on the timer to start it.
• For a one-time non-cancellable single-shot timer: QTimer::singleShot(1000, this, SLOT(doit()))
Example:
StopWatch::StopWatch( QWidget* parent ) : QLabel( parent )
{
QTimer* timer = new QTimer( this );
timer->start( 1000 );
connect( timer, SIGNAL( timeout() ),
this, SLOT( shot() ) );
}
void StopWatch::shot()
{
_secs += 1;
QString str;
str.sprintf("%d:%02d", _secs / 60, _secs % 60);
setText( str );
http://qt.nokia.com/4.5/timers.html
55
57. Qt GUI Classes
• Extends QtCore with GUI functionality QtOpenGl QtSvg QtWebKit QtXmlPatterns Qt3Support
• UI application base class
• UI components : set of widgets and dialogs QtGui QtSql QtXml QtNetwork QtScript Phonon
• Widget layout management and classes for UI Events
QtCore
• All the UI components usually needed
• Not enough?
• Customized components can be done and integrated
with Qt Creator
• Provides rich set of GUI components
and supporting functionality
• Model-View-Controller (MVC) Item views
• Styles – ensuring native or custom look
and feel on target platforms
• Font-aware layout system
• Accessibility classes
• Canvas component with Widget support
57
58. QApplication
• Initializes application settings
• Palette, font
• Receives events from window system and dispatches them to widgets
• Defines application’s look and feel
• Provides localization of strings
• Knows application’s windows
• widgetAt()
• Use global qApp pointer to access QApplication instance
58
59. Windows
• Any widget is a window, unless it has a parent
• In addition, Qt has QMainWindow class
• Can be created with Qt Designer
Menu bar
Toolbars
Dock widgets
Central widget
Status bar
59
61. Toolbar
• Create actions in the same way as to menus
• Add actions to toolbars
QToolBar *fileToolBar;
fileToolBar = new QToolBar(MainWindow);
fileToolBar->setObjectName(
QString::fromUtf8("fileToolBar"));
fileToolBar->addAction(actionOpen);
61
63. Input & Selection Widgets
• Push buttons
• Selection buttons
• Text input
• Line input
• Plain text input
• Plain & rich text input
• Spin boxes
• Dial
• Scroll bars
• Sliders
63
64. Group & Layout Widgets
• Horizontal, vertical, grid layouts
• Tab widgets, group boxes, etc.
• Spacers
Qt Designer Result
64
65. Action Widgets
• QMainWindow
• Menus
• Menu items
• Inner menus
• Mapped to Options menu in S60 builds
• Tool bars
• Tool bar items
• Each menu or tool bar item is related to an Action (QAction)
• Text, icon
• Can be dragged from menu to toolbar
• Can be the same in both
65
66. Dialogs
• QInputDialog
• Lets users provide one-line input
• QMessageBox
• Displays message and icon to user
• QProgressDialog
• Displays progress of lengthy operations to user
• QDialog
• Base class for all dialogs
• QColorDialog
• QFileDialog
• QFontDialog
66
67. Geometry Mgmt with Layout managers
Classes used
QHBoxLayout, QVBoxLayout, QGridLayout, QStackedLayout
Each widget should be added to a layout manager
Layout managers may be nested
QWidget *top = new QWidget;
QLabel *nameLabel = new QLabel("Username:", top);
QLineEdit *nameEdit = new QLineEdit(top);
QLabel *passLabel = new QLabel("Password:", top);
QLineEdit *passEdit = new QLineEdit(top);
QVBoxLayout *vlay = new QVBoxLayout(top);
QHBoxLayout *nameLayout = new QHBoxLayout;
QHBoxLayout *passLayout = new QHBoxLayout;
vlay->addLayout(nameLayout);
vlay->addLayout(passLayout);
nameLayout->addWidget(nameLabel);
nameLayout->addWidget(nameEdit);
passLayout->addWidget(passLabel);
passLayout->addWidget(passEdit);
top->show();
67
69. Event Processing and Painting
• Painting takes place when QWidget::paintEvent() function call is received by
the application
• Two ways to request repaint (QWidget member functions)
• repaint() – causes immediate call to paintEvent()
• Avoid
• Use only in animations, where immediate repaint() needed
• update() – causes a repaint event to be queued
• Several update() calls are combined by Qt
• Does not cause flickering
69
70. Basic Drawing
QPainter QPaintEngine QPaintDevice
• QPainter performs drawing operations
• Specifies QPaintDevice instance to draw
• QPaintDevice is an abstraction of 2D space that can be painted on (such as
QBackingStoreDevice)
• Drawing can be done on instances of QWidget, QPrinter, QPixmap, QImage,
QPicture, QGLPixelBuffer, and QGLFrameBufferObject, in other words anything
inheriting QPaintDevice
70
71. QPainter
• Draw different shapes
• Polygon, rectangle, ellipse, pie, line, arc, text
• Specify pen width and style
• Solid, dash, dot
• Enable/disable antialiasing
• Set brush
• No brush, gradient color, texture
• Use transformations
• Translate, rotate, scale
• Save and restore drawing context
• QPainter settings
71
72. Added value to AVKON controls
• Gradient colors
• Transformations
• Timed transformations, i.e., animations
• Image composition
• Color transparency, 8-bit alpha channel
• Graphics view
• With graphic items
• With graphics widgets
72
73. Gradient Colors
• Linear – Color interpolation between start and end points
• Radial – Interpolation between focal and end points on a circle
• Pattern can be repeated or reflected outside the end point
• Conical – Counter-clockwise interpolation around a point
QPainter p(this);
QLinearGradient g(0, 0, 100, 100);
g.setColorAt(0.0, Qt::white);
g.setColorAt(1.0, Qt::blue);
p.setBrush(g);
p.drawRect(0, 0, 100, 100);
• Also easy to add repeats and reflections, e.g.:
QGradient::setSpread(QGradient::ReflectSpread);
73
76. Graphics View
• Provides a surface for managing and interacting with number of custom-made
2D graphical items
• Event propagation architecture provided
• Allows precise double-precision interaction capabilities for the items on the scene
• Items can handle key, mouse press, move, release and double click events
• Tracks mouse movement
• Uses Binary Space Partitioning tree to provide very fast item discovery
• Items may be widgets
• Fancy way to add transformations to the scene
• Automatic collision detection
• Main components
• Graphics Item
• Graphics Scene
• Graphics View
76
77. Graphics Scene – QGraphicsScene
• Container for item objects
• Provides a fast interface for managing a large number of items
• Propagates events to each item
• Manages item state (selection, focus)
QGraphicsScene scene;
QGraphicsItem *rect = scene.addRect(QRectF(0, 0, 100, 100));
scene.addItem(newGraphicsItem);
QGraphicsItem *item = scene.itemAt(50, 50);
// item == rect
78
78. Graphics View - QGraphicsView
• The view widget for displaying the contents of a QGraphicsScene
• One scene may display on one or more graphics views
• You can add a QGraphicsView directly from the UI Designer
• Like an empty canvas for your Graphics Items
• Convenient and efficient use of transformations
• Uses QMatrix or QTransform
• rotate()
• scale()
• translate()
• shear()
79
79. Graphics View Usage
• Create an instance of QGraphicsScene
• Create a view to the scene using QGraphicsView, and insert it like any other
widget into your layout
• Create QGraphicsItems to the scene
• For each item, set its position and other properties to your liking
• Add each item with scene->addItem(item);
• Optionally, create custom items by subclassing QGraphicsItem (or a subclass)
• As a minimum, you need to implement boundingRect() and paint(QPainter*,const
QStyleOptionGraphicsItem*,QWidget*)
80
80. Graphics View – QGraphicsItem
• Graphical item on the screen
• Several standard item classes exist: rectangle, ellipse, text
• Items live in their own local coordinate system.
• Coordinates are usually centered around its center point (0, 0), and this is also the
center for all transformations.
• Item features
• Mouse press, move, release, double click, mouse hover event, wheel event, context
menu events
• Keyboard input focus, key events
• Drag and drop
• Grouping
• Z-order
• Collision detection
• Set a shape for your items
• Override collision detection function if needed
81
81. Animations
• Single items can be animated by using a QGraphicsItemAnimation
• QGraphicsItemAnimation can animate an item by interpolating the items position and
transformation over a timeline
QGraphicsItem* myitem = ...;
QTimeLine* timeline = new QTimeLine(500);
timeline->setFrameRange(0,100);
QGraphicsItemAnimation* animation = new QGraphicsItemAnimation;
animation->setItem(myitem);
animation->setTimeLine(timeline);
animation->setPosAt(0.0,QPointF(0.0,0.0));
animation->setPosAt(0.5,QPointF(100.0,100.0));
animation->setPosAt(1.0,QPointF(0.0,50.0));
timeline->start();
82
82. Transformations
• View can transform scene’s co-ordinate system
• Implement slots, which implement the transformations
• Slots connected to widgets signals
• Easy to add transformations to graphic view items or to the whole view
QTransform transform;
transform.translate(50, 50);
transform.rotate(45);
transform.scale(0.5, 1.0);
view.setTransform(transform);
// Also available:
view.rotate(45);
83
84. Animation Framework – new in Qt 4.6
• Helps build highly animated, high-performance GUIs without
the hassle of managing complex structures, timers, and easing
curves or state graphs
• The framework makes it easy to animate any QObjects,
including QWidgets, by allowing Qt properties to be animated.
• Graphics views are not left out; one can animate
QGraphicsWidgets and new QGraphicsObjects which inherit
from QGraphicsItem (and thereby enable properties).
• Animations are controlled using easing curves and can be
grouped together.
• The API is easy to grasp with functions such as start(), stop(),
pause(), and currentTime().
• The animation framework also plugs into the new Qt
Statemachine by allowing an animation to be played when
transitions are triggered. The state machine framework is
introduced in 4.6
85
86. Qt – Modules (OpenGL)
• Offers classes that make it easy to use OpenGL in Qt applications
• Provides an OpenGL widget class that can be used just like any other Qt widget,
except that it opens an OpenGL display buffer where you can use the OpenGL
API to render the contents
• Implemented as a platform-independent Qt/C++ wrapper around the platform-
dependent GLX, WGL, or AGL C APIs
• The functionality provided is very similar to Mark Kilgard's GLUT library, but
with much more non-OpenGL-specific GUI functionality, i.e. the whole Qt API
QtOpenGl QtSvg QtWebKit QtXmlPatterns Qt3Support
QtGui QtSql QtXml QtNetwork QtScript Phonon
QtCore
87
87. Qt Open GL/3D Classes
•OpenGL is a standard API for rendering 3D graphics
•Allows you to build your user interface in Qt, display and
manipulate 3D model in OpenGL®
•Integrates OpenGL canvas with Qt
•Provides frame buffer and pixel buffer abstraction
•Supports accelerating 2D painting with OpenGL
•Mix 2D painting and 3D scenes
88
89. Declarative UI Designer
• For programmers and designers
• expressive declaration language to allow describing how UI’s should look and behave instead of how they are constructed
• Create state-of-the-art, visually appealing user interfaces
• Utilizing declarative UI technology
• Supports both visual and code editing
• Target mobile/embedded and desktop
platforms
• Enabling transition and manipulation of individual component building blocks
• Expose Qt objects and properties to JavaScript
90
Public
91. Red Rectangle with QML
// grant access to basic elements
import Qt 4.6
• QML = Qt Modeling Language
• Inspired by Javascript
// a red rectangle
• Specify user interface declaratively
Rectangle {
• The “flow” of the application id: RedRectangle
• QGraphicsView and QtScript below width: 400
• Qt Creator support height: 200
color: "red"
}
92
92
92. Elements
A Text Element over
Traditional QPushButton an Image Element
Elements are
not restricted
93
93
94. Script
• An ECMAScript (Javascript) block can be the value of a
property inside QML
• Enables complex logic at QML level
• Enables more advanced binding
95
95
95. Declarative UI - what else will there be
• States
• Transitions
• Animations
• With bindings to Qt C++ you can get access all the mobile features you need!
96
97. Qt – Modules (Phonon) QtOpenGl QtSvg QtWebKit QtXmlPatterns Qt3Support
• Multimedia framework for audio and video content
QtGui QtSql QtXml QtNetwork QtScript Phonon
• Support playback of the most common formats QtCore
• Media can be read from files or streamed over a network
• It is just FW, backend provide the actual functionality
• Windows: DirectX and DirectShow 9 or higher
• Linux: GStreamer
• Mac: QuickTime
• S60: MMF Phonon::VideoPlayer *player =
• Implementation in Qt for S60 beta
new Phonon::VideoPlayer(
• Based on three basic concepts Phonon::VideoCategory,
• Media objects parentWidget);
• Manages media sources player->play(url);
• Media control: start, stop, pause etc
• Sinks
• Outputs media (video rendering to widget, audio to sound card)
• Paths
• Used to connect media objects and sinks
• Enables media graphs
98
99. Qt Convenience Classes
• QMovie
• QMovie class is a convenience class for playing movies with QImageReader
• Incremental loading of animations or images
• QLabel::setMovie()
• QSound
• Access to the platform audio facilities
• Provides cross-platform sound support
• On Microsoft Windows, the underlying multimedia system is used
• Only the WAV format is supported for the sound files
• On X11, the Network Audio System is used if available, otherwise all operations work silently
• NAS supports WAV and AU files
• On the Macintosh, all QuickTime-supported formats are supported
• QVideoPlayer
100
101. Qt – Modules (Sql)
QtOpenGl QtSvg QtWebKit QtXmlPatterns Qt3Support
• Provides database integration to Qt applications
• Divided to three layers
QtGui QtSql QtXml QtNetwork QtScript Phonon
1. UI Layer
• Provides classes to link the data from database to QtCore
data-aware widgets
• Designed to work with Qt's model/view framework
2. API layer
• Provides Qt’s abstracted database-independent SQL
API
3. Driver layer
• Provides low-level bridge between the specific QSqlDatabase db =
databases and the SQL API layer QSqlDatabase::database("sales");
• Uses driver plugins to communicate with the different QSqlQuery query
databases ("SELECT Lastname,
• Several drivers are supplied with Qt City FROM Names", db);
102
102. Connecting to a Database
• Choose driver(s) to use in the static method
QSqlDatabase::addDatabase(QString)
Driver type Description
QDB2 IBM DB2, v7.1 and higher
QIBASE Borland Interbase Driver
QMYSQL MySQL Driver
QOCI Oracle Call Interface Driver
QODBC ODBC Driver
QPSQL PostgreSQL v6.x and v7.x FDriver
QSQLITE SQLite version 3 or above
QSQLITE2 SQLite version 2
QTDS Sybase Adaptive Server
103
103. Connecting Example
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("bigblue");
db.setDatabaseName("flightdb");
db.setUserName("acarlson");
db.setPassword("1uTbSbAs");
bool ok = db.open();
if ( !ok )
qFatal() << "Error opening database: “ << db.lastError();
104
104. Invoking SQL Queries
• The class QSqlQuery can be used to run any SQL query
• This includes select statements, insert statement, and even statements for creating new
tables
• To run a query, create an instance of QSqlQuery, and run the exec() method specifying
the statement as a parameter:
QSqlQuery query;
if ( !query.exec( "SELECT name FROM
author" ) )
...
• An optional argument can be given to the constructor specifying which database to use
• Transaction support
• QSqlDatabase::transaction(), QSqlDatabase::commit(),
QSqlDatabase::rollback()
105
106. Qt – Modules (XML)
QtOpenGl QtSvg QtWebKit QtXmlPatterns Qt3Support
•QtXml
• Provides C++ implementation of SAX and DOM QtGui QtSql QtXml QtNetwork QtScript Phonon
style XML parsers
• Provides a stream reader and writer for XML QtCore
documents
• XSLT support
•QtXmlPatterns QXmlStreamReader xml;
• XQuery support for Qt xml.addData( data );
while (!xml.atEnd())
• Simple SQL-like query language for traversing {
XML documents
xml.readNext(); ...
• Can select and aggregate XML elements of // do processing
interest and transform them for output as }
XML or in some other format
107
107. XML APIs
• Qt provides three different means of accessing XML data:
• SAX (version 2), which provides a sequential view on the data using call backs
• Stream Reader/Writer - also a sequential view, but control is in the app using a readNext()
method - makes it easier to write recursive decent parsers
• DOM (level 1 and 2), which provides a tree view on the data
• In order to use the XML support, add QT += xml to your QMake files
• Using SAX is easiest with QXmlDefaultHandler:
class MyHandler :public QXmlDefaultHandler { ... }
MyHandler handler;
QXmlSimpleReader reader;
reader.setContentHandler( &handler );
reader.setErrorHandler( &handler );
108
109. Qt – Modules (Network)
• Classes for writing TCP/IP clients and servers QtOpenGl QtSvg QtWebKit QtXmlPatterns Qt3Support
• Makes network programming
easier and portable QtGui QtSql QtXml QtNetwork QtScript Phonon
• Support for QtCore
• Lower level protocols (TCP and UDP)
and higher level application protocols (FTP and HTTP)
• Seamless integration with progress widgets and any IO device
• Host Name resolving services and URL parsing, SSL support and much more
QHttp http;
connect(http, SIGNAL(done(bool)), this, SLOT(done(bool)));
http->get( “http://overtheair.org/amazingApi.jsp?action=doGreatThings”);
void MyClass::done(bool error)
{ QString data = http->readAll(); //handle data }
110
110. Networking
• Easy to use with high-level classes
• QHttp (QNetworkRequest, QNetworkAccessManager, QNetworkReply)
• In most cases, use WebKit directly
• QFtp
• QTcpServer
• QTcpSocket
• QUdpSocket
• QNetworkProxy added in Qt 4.5
• Add network module to your project file
• QT += network
111
111. Network Access
• QNetworkAccessManager
• Asynchronous API for sending and receiving data
• Intuitive API for put/post/get/head
• Modify or inspect headers in request and reply
connect(manager, finished(QNetworkReply*)),
this,SLOT(replyFinished(QNetworkReply*)));
QNetworkRequest req(QUrl(“http://host.com/foo”));
manager->get(req);
void replyFinished(QNetworkReply *reply)
{
//some checks to verify reply
QByteArray data = reply->readAll();
}
112
113. Qt – Modules (WebKit)
QtOpenGl QtSvg QtWebKit QtXmlPatterns Qt3Support
• Classes for displaying and editing Web
content
QtGui QtSql QtXml QtNetwork QtScript Phonon
• Web content can be enhanced with
native controls QtCore
• Based on open-source WebKit engine
• Ported to use Qt
• Rendering
• Text Handling
• Network Access
• Integrated part of WebKit project, uses
WebKit’s platform abstraction QWebView *view = new QWebView(parent);
view->load(QUrl("http://qt.nokia.com/"));
• Qt Style API to engine: view->show();
• QWebView, QWebPage and QWebFrame
114
114. Interact with Web Services
• QtWebKit allows
• Intuitive use of network resources
• Exposing QWidget to HTML and QObject to JavaScript
• Calling JavaScript from Qt and vice versa
JS
Qt
OS specific
APIs
115
115. QWebView and QWebPage classes
• QWebView inherited from QWidget QWebView
• Renders the content in QWebPage
• Easy to embed wherever widget could be used
QWebPage
• QWebPage provides access to the document structure in a page QWebFrame
• Frames
• Navigation history
• Undo/redo stack for editable content
• Each QWebpage has one QWebFrame object as its main frame
• HTML documents can be nested using frames
116
116. function setStatus() {
Javascript twit.updateStatus( statusupdate.text );
}
statusupdate.returnPressed.connect(this,setStatus);
QWebFrame *frame = view->currentFrame();
//You can inject JavaScript to be executed
frame->evaluateJavaScript(“myAmaging JS Stuff”);
//You can expose any QObject to the web view
MyQTwitter *twit = new MyQTwitter()
frame->addToJavaScriptWindowObject(“twit”,twit);
//do what ever you want with native APIs
//that you can call directly from Qt
CRRSensorApi::FindSensorsL(sensorList);
117
117. Exposing Widgets – 1(2)
• WebKit can place QWidget’s in the web environment
• Use HTML/script to control UI and infrastructure
• Two approaches
• Host widget inside web environment
• Expose object to script environment
• …or call script from C++ side
• Why would you want to do this?
• Simple updates (redeploy a script file)
• Easy to reuse web design for Look & Feel
• Easier interaction with web services
118
118. Exposing Widgets – 2(2)
• Place QWidget in web environment
• QWebPage::createPlugin()
• QWebPluginFactory
• <object type=“application/x-qt-plugin” classid=“MyNiceWidget” …>
QObject* createPlugin(const QString &classid, const QUrl &url,
const QStringList& paramNames, const QStringList ¶mValues )
{
if (classid==“MyNiceWidget”)
return new MyNiceWidget;
return 0;
}
119
119. Work with Exposed Objects
• QWebFrame::addToJavaScriptWindowObject
• QObjects expose metaobject information
• Properties can be read and altered
• Slots can be called
• Connect statements can be made
frame->addToJavaScriptWindowObject(“twit”,twit);
function setStatus() {
twit.updateStatus( statusupdate.text );
}
statusupdate.returnPressed.connect(this,setStatus);
120
120. Interoperating with JavaScript
• Each web frame has a JS context
• QWebFrame::evaluateJavaScript
QWebFrame *frame = view->currentFrame();
frame->evaluateJavaScript(…)
• Returns a variant
QVariant value = frame->evaluateJavaScript(“1+1;”);
// value.toInt() == 2;
121
121. Hybrid Development
Approachability of
Programming
Environment
Un
at Are
Easy
ta a
in
WRT
ab
• Hybrid applications combine easily approachable web
le
technologies and powerful and scalable Qt C++
• Qt already includes a rich selection of features for web and Difficult
Qt C++
Size of
hybrid development Project
Small Large
• QtWebKit module: embed web content from servers, local
files or application’s resources into Qt applications
• QtScript module: make Qt applications scriptable Hybrid Applications
• Both QtWebKit and QtScript provide a bridge between the Qt C++
Application
JavaScript execution environment and the Qt object model, to
allow for custom QObjects to be scripted. HTML, CSS,
JavaScript
• QtXMLPatterns module: shape and mash up XML date yielding
HTML output
• QNetworkAccessManager: interact with server side URL APIs Browser/ Standalone
Web runtime
Application *)
Services written in
Qt C++, Declarative
UI, Access to Qt
*) Planned future functionality
122
Public
122. Hybrid apps
• So you can run JS and HTML inside Qt application… What are the differences
when compared to a WRT widget?
WRT Widget running on top of webkit Qt application
Webkit QWebView running webkit
Widgets HTML,
CSS, Same HTML, CSS,
JavaScript JavaScript
Platform
Services
Native APIs Native APIs incl. Qt Mobility APIs
Platform
Services
implementation Platform
Services
implementation
123
123. Webview Demo
• Pure JS content run on top of Webkit
• Demonstrates different applications & look and feel
• BBC News
• News (Iphone style)
• Rock-Paper-Scissors
• Tic-Tac-Toe
• Calculator
• Bubble
• Statistics:
• 300 lines of C++ code (flick support ~200 lines)
• Size of .sis file: 20 kB
• Development time: approx. 5 hours
124
124. Key selling points in the hybrid approach
• No feature restrictions!
• Portable where ever Qt is available (which is everywhere - soon)
• Utilize web developer skills to make the apps
• Qt native skills to implement”platform services”
• Qt script generator http://labs.trolltech.com/page/Projects/QtScript/Generator
• Mixing native and HTML UI
• Interesting scenarious coming f.ex with Orbit widgets
• Tools might be problematic (migrating web tools and native (Qt Creator))
• We can make hybrid approach even for compelling by providing ready
framework where existing widgets can be plugged in
125
127. What is Qt for Symbian?
• Qt APIs have been implemented on top of OpenC/Symbian APIs
• The purpose is to have Qt programs running on the Symbian
platform
• Cross-platform applications
• There will be a separate library called Orbit (built on top of Qt
modules) which provides additional Symbian UI framework APIs in the
future
• Qt modules are compiled as Symbian DLLs and can be used in a
Symbian environment as is
• From the perspective of a developer, Qt can be considered as a set of
libraries to use for UI implementation, otherwise it’s just Symbian
development
128
128. Installing Qt for Symbian
• The Qt modules’ source code, installation guide and a Windows installer are
downloadable from
http://qt.nokia.com
• The Qt tools are compiled for Symbian platform
• The Qt modules are compiled using Symbian build tools
• As a result, a bunch of Qt*.dll and Qt*.lib files are produced into SDK emulator
folders (epoc32)
• For devices, pre-made .sisx files are provided
• Qt libraries can currently only be compiled for devices using the RVCT tool chain
129
129. Installing Qt 4.6 beta to the device
• Remember to have Symbian 3rd Edition FP1 or newer device
• Not sure what device you have? Check out from http://www.forum.nokia.com/devices/
• Install the following
• From Open C plugin (http://www.forum.nokia.com/openc)
• pips_s60_1_6_SS.sis: Pips 1.6
• In [Symbian_SDK]nokia_pluginopencs60opencsis
• openc_ssl_s60_1_6_SS.sis: Open C SSL 1.6
• In [Symbian_SDK]nokia_pluginopencs60opencsis
• STDCPP_s60_1_6_SS.sis: STDCPP 1.6
• In [Symbian_SDK] nokia_pluginopencpps60opencppsis
• qt_4_6_beta.sis: Qt for Symbian 4.6 beta
• The Qt libraries, In the folder where you installed Qt
• fluidlauncher.sis: Demo apps for Qt 4.6 beta
• Demo applications
• In the folder where you installed Qt, f.ex C:Qt4.6.0-beta
• Yes, in the final version we will have a simpler solution ;)
130
130. ”smart installer” - Qt installer for Symbian
The opportunity The problem The solution
A Smart Installer tool that
+130M Symbian devices Qt libraries need to be
checks whether needed Qt
could run cross-platform Qt post installed – most
version is available on the
applications already during consumers might not
device – and if not, it will
this year bother
handle the installation
Details
•Nokia is working on a tool called Smart Installer for Symbian devices
•The expected availability is 1Q 2010
•A piece of code is to be packaged together with the Qt application targeted for Symbian devices (when
creating the .sis file)
•The Smart Installer will download OTA the needed Qt version to the handset if it is not already present
131
131. Carbide.c++ 2.0
• Since version 2.0 all editions are free of charge
• Qt for Symbian support!
• New to Carbide? View the Getting Started with Carbide.c++
Express Screencast, which will take you through the basics
of creating, building, and deploying your first application.
• http://www.forum.nokia.com/info/sw.nokia.com/id/af80987a-
a72d-44cf-bf00-
1926be01058c/Carbide_cpp_Getting_Started_v1_1_en.exe.html
• Bug reports : Carbide Help menu, ”New Bug Report”
132
136. First Qt Program
#include <QtGui/QApplication>
#include <QtGui/QLabel>
int main(int argc, char* argv[])
{
QApplication hwApp(argc, argv);
QLabel hwLabel("Hello world");
// Widgets are not visible by default.
// Alternatives: showMaximized(), showFullScreen()
hwLabel.show();
return hwApp.exec();
}
137
137. qmake – example of .pro file Specifies for qmake that:
• application is based on Qt and
CONFIG += qt debug
• debug information is needed
HEADERS += hello.h
SOURCES += hello.cpp
SOURCES += main.cpp
win32 { Platform specific conditions. This
SOURCES += hellowin.cpp mechanism will be used to specify
Symbian/S60 specific details, like
} required capabilities, UIDs etc.
unix {
SOURCES += hellounix.cpp
}
!exists( main.cpp ) {
error( "No main.cpp file found" )
}
win32:debug {
CONFIG += console
}
138
138. Project File Structure
CONFIG += qt debug
HEADERS += hello.h
SOURCES += hello.cpp
SOURCES += main.cpp
win32 {
SOURCES += hellowin.cpp
}
unix {
SOURCES += hellounix.cpp
}
Symbian {
SOURCES += hellosymbian.cpp
}
!exists( main.cpp ) {
error( "No main.cpp file found" )
}
win32:debug {
CONFIG += console
}
• You may also use flags in your code
• Symbian features or changes flagged with Q_OS_SYMBIAN
• S60 dependencies with Q_WS_S60
139
139. Building Qt Application on Symbian
• In a normal Qt way for the Qt part:
• qmake –project
• qmake
• Component description file created (bld.inf)
• Project description file created (.mmp file)
• Extension Makefiles created
• Take care of executing moc, uic, rcc tools
• Integrated like mifconv to the toolchain
• Then, the actual compilation either with
• Generated platform specific Makefile: make debug-winscw
140
141. Platform Security
• Qt programs executed in processes with their own capabilities
• Just like native programs
• If a program accesses a protected Symbian/S60 API, it needs capabilities and/or
secure/vendor IDs
• Capabilities needed by native API calls easy to determine with Carbide.c++
capability scanner
• PlatSecDiagnostics can be used to determine capabilities needed by Qt library APIs
• Set PlatSecEnforcement OFF and diagnostics ON in the epoc32dataEPOC.INI file
• Read possible platform security violations from %TEMP%EPOCWIND.out
142
142. MMP File Definitions in a .pro Project File
• Everything you need in a Symbian OS MMP file, can be defined in the Qt .pro file
• Symbian-specific extensions should be defined inside a special block as shown
below
TARGET = HelloWorld // Not Symbian-specific
TEMPLATE = app // Not Symbian-specific
symbian*:{
// LIBS-keyword as such is not Symbian-specific, but bitgdi library is
LIBS += -lbitgdi
ICON = ./images/myIcon.svg
TARGET.UID2 = 0x100039CE
TARGET.UID3 = 0xA000017F
TARGET.SID = 0xA000017F
TARGET.VID = 0x70000001
TARGET.CAPABILITY = NetworkServices
// Qt app stack typically larger than 8kb
TARGET.EPOCSTACKSIZE = 0x5000
// Min 128Kb, Max 16Mb
TARGET.EPOCHEAPSIZE = “0x20000 0x1000000”
}
• This way the same .pro file would potentially work in other environments as
well
143
143. make command Command Description
make Creates abld and the project makefiles and builds debug
build of the application for the emulator (winscw
udeb).
• Running make command calls
bldmake and abld to build the Qt make debug Creates debug builds (winscw/gcce/armv5 udeb).
make debug-winscw Creates winscw debug build.
application for the S60 environment.
make debug-gcce Creates gcce debug build.
make debug-armv5 Creates armv5 debug build.
make release Creates release builds (gcce/armv5 urel).
make release-gcce Creates gcce release build.
make release-armv5 Creates armv5 release build.
make export Copies the exported files to their destination.
make cleanexport Removes files created with make export.
make mocclean Removes the header and source files created by the moc
tool.
make mocables Runs moc tool on necessary files.
make clean Removes everything built with abld target, exported files
and makefiles.
make distclean As make clean, but also removes all Symbian specific files
created with qmake.
make confclean As make distclean, but also cleans everything generated by
configure call. Note that this command is only available
in the Qt root directory.
make run Launches the application in the emulator.
145
144. Symbian Extensions to Project Files
• A Qt application on Symbian, is a Symbian application written in Qt running on S60 devices.
• All statements that are in a Symbian project defined in the mmp file are defined in the project file
when creating application with Qt in the S60 environment. Executing qmake overrides all
changes made manually to the mmp file.
• Trick : if you really need to have manual changes put the file as read only!
• Target type is specified using TEMPLATE and CONFIG variables in the .pro file.
• TEMPLATE = app value maps to target type EXE in MMP file,
• TEMPLATE = lib, CONFIG variable is used to distinguish between lib and dll target types.
• Name of application executable – use TARGET statement in .pro file (maps to TARGET in MMP file).
Example: TARGET = QtS60HelloWorld
• Symbian specific definitions in the project file should be separated from other definitions using a
Symbian keyword. Example:
symbian: {
TARGET.UID2 = 0x100039CE
TARGET.UID3 = 0xA000017F
}
146
145. Symbian Extensions to Project Files
• Some other examples of Symbian specific keywords:
• TARGET.SID = 0xA000017F
• TARGET.VID = 0x70000001
• TARGET.EPOCSTACKSIZE = 0x5000 // 20kb
• TARGET.EPOCHEAPSIZE = 0x20000 0x1000000 // Min 128kb, Max 16Mb
• TARGET.CAPABILITY = NetworkServices
• The DEFINES keyword can be used to add MACRO statements to the mmp file.
• QMAKE_CXXFLAGS can be used for setting compiler-specific options. The
keyword is followed by the specific compiler:
QMAKE_CXXFLAGS.CW += -O2
QMAKE_CXXFLAGS.ARMCC += -O0
147
146. Symbian extensions to project files
• RSS_RULES keyword for adding information to the _reg.rss file
• BLD_INF_RULES keyword for adding information to the bld.inf file
• Bunch of other extensions can be found in the Qt for S60 documentation – see
more in:
http://library.forum.nokia.com/topic/Qt_for_S60_Developers_Library/GUID-
97A34C6E-9F2B-4743-86F8-563362F7047A_cover.html
• And http://pepper.troll.no/s60prereleases/doc/qmake-variable-reference.html
148
147. Libraries
• Some libraries are automatically added to the mmp file when generating
the file. These libraries are:
• libc, libm, euser, libdl and QtCore,
• static library libcrt0 for QtCore applications,
• static library qtmain for QtGui applications,
• QtGui, avkon, eikcore, eiksrv, ws32, apparc, cone, eikcoctl, bafl and efsrv for QtGui
applicaitons.
• Qt libraries are added to the project file using the QT variable:
QT += network
• If other platform-specific libraries need to be added to the project, this can
be done by adding the LIBS variable to the project file with the appropriate
library name preceded with a ‘–l’ prefix:
LIBS += -lbitgdi –lfbscli
149
148. Platform Security cnt’d
• Qt programs executed in processes with their own capabilities
• Just like native programs
• If a program accesses a protected Symbian/S60 API, it needs capabilities and/or
secure/vendor IDs
• Capabilities needed by native API calls easy to determine with Carbide.c++
capability scanner
• PlatSecDiagnostics can be used to determine capabilities needed by Qt library APIs
• Set PlatSecEnforcement OFF and diagnostics ON in the epoc32dataEPOC.INI file
• Read possible platform security violations from %TEMP%EPOCWIND.out
150
152. Go nuts and mix Qt with Symbian APIs
• As Qt is not a runtime you can always use native apps to fill the gaps
• Mobility APIs progressing and removing the need for many cases
154
153. Exceptions/Leaves
• Isolate all leaving Symbian OS code from Qt code
• Trap all leaving functions and return error code to Qt
… or …
• Use the global conversion macros and functions provided by the Qt for
Symbian release
int PainterWrapper::ConstructPainter() {
TRAPD(error, activePainter = CActivePainter::NewL());
return error;
}
// …or something like…
HBufC* buf=0;
// this will throw a std::bad_alloc because we've asked for too much memory
QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(buf = HBufC::NewL(100000000));
155
154. Separating Qt and Symbian implementations 1/2
• Symbian code should be separated from Qt code so that it can be replaced
with another platform-specific code when changing the platform. Private
implementation (aka pimpl) is an idiom that is used in Qt, and it can be
utilised to separate platform-specific code — different platforms have different
implementations of the private class. Binary compatibility can be retained with
this idiom.
• The idea of cross-platform implementation is to have the public interface of
the class the same for all platforms; the private implementation can then be
platform specific.
156
155. Separating Qt and Symbian implementations 2/2
• The main principles for private implementation are:
• The public class has to have a pointer to the private class
AOWrapper::AOWrapper(QObject *parent)
: QObject(parent)
{
d_ptr = new AOWrapperPrivate(this);
}
• The constructor of the private class creates a pointer to the public class passed as a parameter:
AOWrapperPrivate::AOWrapperPrivate(AOWrapper *wrapper)
: q_ptr(wrapper)
{
}
• The q_ptr pointer can be used to refer to the public class from the private class and the d_ptr pointer
can be used to refer to the private class from the public class.
• For examples of using the private implementation you can have a look f.ex at the Mobile Extensions
157
156. Private Implementation
• The problem: Maintaining Binary Compatibility
• Adding, removing or reordering members in public classes would break binary
compatibility
• Different implementations of the same class in different platforms
• Need a way to hide implementational details from the class header
• Private Implementation, P-IMPL, is a general design pattern providing a
solution for this problem
• Used throughout Qt with a few exceptions
• QColor, QModellndex, QMatrix, Q*Event
158
157. Private Implementation in General
// a.hh // a.hh // a.cpp
class A { struct D; struct D {
... int x;
private: class A { int y;
int x; ... };
int y; private: ...
}; D* d_ptr;
};
159
159. Qt and Active Objects
• Active scheduler is created when the S60 GUI Framework is initialized in
s60main
• Happens before main() in your Qt application is called
• How to use Qt and Active Objects:
• An example application exists:
http://www.forum.nokia.com/info/sw.nokia.com/id/63313e06-8fd7-4a68-8610-
80dd7ee22745/Qt_for_S60_Examples.html
• And also documentation:
http://www.forum.nokia.com/info/sw.nokia.com/id/c41e7898-2dd8-4f23-a629-
d27727519ffa/Qt_for_S60_Developers_Library.html
161
160. Separating Symbian specific
implementation
• When you need to write Symbian specific code use the following macro
#if defined(Q_OS_SYMBIAN)
#include <e32std.h>
#endif
• One good way to separate Symbian code is to have in in a separate DLL
(plugin)
162
161. Lucian – the floor is yours
• Please take it…
163
162. Part 6.
Closing
Please take my business card!
;)
164
163. We’ll be making it easy for you
• All you need is Qt creator – no SDKs ;)
• Integrated with Remote Device Access (RDA) - you don’t even need a device ;)
• http://www.forum.nokia.com/rda
• No promises here about dates or months yet…
Combine hybrid framework with this one
– isn’t it creepy how easy we can make it for you?
165
http://www.youtube.com/watch?v=TmFn90Zx2oo
164. Nokia + Ovi Developer Story | 167
Nokia native dev offering, redefined
1= Nokia cross-platform SDKs that you’ll love – with a
money back guarantee (as it’s free)
2= Ovi APIs. Amazing features in your apps – take
the Ovi social network to be a part of your
solution
3= Ovi Store. Sell your app to hundreds of millions
167