Upload
joel-cummings
View
228
Download
1
Embed Size (px)
Citation preview
Introduction to QtBuild Great Apps Using Qt
Jeff Alstadt
My name is Jeff Alstadt I
work as a Senior Developer at Litholink, a LabCorp company
am a passionate C/C++ and .NET developer worked with Qt in 2011 while at Centare love open source and believe it is the right way
to do software development am an avid technical speaker and blogger
Introduction
Today we are talking about
This Is Qt 5
Qt is an open source cross platform UI toolkit for the C++ platform
Qt is used by over 500,000 developers Although digia has taken over support the Qt
project, Qt is still a strong contender for embedded Linux (RTOS), desktop UI development (Windows, Mac and Linux), and mobile devices (tablet, phone)
What is Qt?
Qt was founded in 1991 in Oslo, Norway by Erik Chambe-Eng and Haavard Nord
Both Erik and Haavard had founded Trolltech on 4 March 1994.
Trolltech‘s IPO came on the Oslo Stock Exchange in July 2006
In 2001 Qt introduced Qtopia which was an application platform for embedded Linux-based devices such as mobile phones, home media and etc.
Qt Founders
Qt Founders
The toolkit was called Qt becuase the letter Q looked appealing in Haavard‘s Emacs font and “t“ was inspired by Xt, the X toolkit
So what does the Qt ecosystem look like
Actually not, over 500,000 developers have applications built on Qt technology
Even though Nokia sold Qt to Digia, Digia has promised 15 M Euro investment in Qt research and development and ecosystem activities
Commercial licensing ensures future funding of Qt development
The next Blackberry will be using Qt as its UI framework
Qt mobile apps have been successfully ported to iOS and Android
But isn’t Qt dead?
#1 in multi-platform support #1 in developer experience #1 in creating great user experiences Belief in dual licensing model Strong value generating ecosystem Open business architecture
Digia’s Goals for Qt
Actually Qt is enabled for the web. Using Qt WebKit Qt developers can develop apps using C++, QML and HTML5/JavaScript.
Qt WebKit provides facilities for rendering of HTML, XHTML, SVG, CSS and JavaScript
QtWebKit Bridge provides a bridge between the JavaScript execution environment and the Qt object model.
Qt Webkit is based on the Open Source WebKit Engine
But Qt can’t handle web…
The Tulip Container Classes The Arthur Paint System The Interview Framework The Scribe Classes Qt Main Window Classes Graphics View Qt Network Module Resource System Unit Testing Framework
Fundamental Technologies of Qt
Qt Creator – cross platform C++ debugger and developer designed specifically for Qt
Qt Visual Studio add-in – provides Qt integration with Visual Studio 2008, 2010 and 2012
Qt Simulator - A fast and lightweight simulator for Qt applications running on Nokia devices.
Eclipse Integration Plugin Qt Teambuilder – distributed C/C++compilation Qt Mobility – mobile API Qt SDK Qt Quick Qt Webkit
Qt Development Tools
The Qt Lighthouse project was a project started to gain advancement in providing Qt ports to iOS and Android
The Lighthouse project is the project that will allow Qt to be deployed on mobile devices
Qt Lighthouse
The Necessitas project is a community driven Lighthouse based port of Qt to Android
It has a plugin for Qt Creator to do Android development
An installer application for Android called Ministro exists Ministro is responsible for downloading the Qt
libraries specific to that Android device
Qt Meets Android
The Qt Lighthouse project was an initiative to get Qt running on the iOS platforms.
Qt Meets iOS
Qt Overall Architecture
Here we will get into Qt concepts QObject Meta Object Compiler (MOC) Qt Container Classes Signal Slot System Qt Property System Qt Event System Qt Model View Concept Qt Widgets (QWidget) Qt Graphic View (QGraphicView)
Let’s get technical with Qt
Most objects in Qt inherit from QObject This provides your custom Qobject classes to
have Signals and slots support Property Support Memory Management Support Introspection
QObject
A program that handles Qt’s C++ Extensions How it works:
Moc looks for the Q_OBJECT macro Once found moc will produce a C++ source file containing
the meta-object code that is required for Signals and slot mechanism Run-time type information Dynamic Property System
Moc produces another header and source file with the moc_mycppfile.cpp These need to be included in the make file so that the code
can be compiled and linked.
Meta Object Compiler
Qt utilizes many of the STL collection classes and introduces some of its own
These include QList QMap QStack QQueue QSet QHashMap QVector
Qt Container Classes
Specific concept in Qt every Qt developer needs to know
Implements simple Observer Pattern
Type safe Decoupled Objects inherited from
QObject will only receive the signal notifcations
connect connects the object signal to the respective slot
Signals and Slots
Signal Slot Code Example
The Qt system provides a means to set any property in the Qt Meta-Object System
The Qt solution works with any standard C++ compiler Qt supports
Q_PROPERTY is a macro that is used to declare property
This declaration must be done inside a QObject
Qt Property System
An event is an object or a set of objects derived from the abstract class QEvent
Events represent things that have happened either within an application or as a result of outside activity that the application needs to know about
Events are recieved and handled by instance of a derived QObject class
Qt Event System
QResizeEvent (Window Resizing) QPaintEvent (Window Repainting) QMouseEvent (Mouse Input) QKeyEvent (Keyboard Input) QCloseEvent (Window close)
Common Qt Events
In Qt, we can utilize the QCoreApplication to create and send our own custom events.
To do this, we utilize sendEvent() and postEvent(). sendEvent() processes the event immediatly. postEvent() posts the event on queue for later dispatch
When Qt‘s main event loop runs, it will then dispatch all posted events.
To create a custom Qt Event type, simpily subclass your event from QEvent and ensure it has an event number that is greater than QEvent::User (1000 presently in 4.8)
For all events, check here
Sending Events
Qt has an advanced Model View archictecture concept that was inspired from the MVC approach
Instead Qt utilizes a delegate instead of a controller
The delegate is used to provide a fine control over how items are rendered and edited
For Qt specific views, Qt provides the appropriate delegate for that view
Model View
QStringListModel QStandardItemModel QDirModel QSqlQueryModel QSqlTableModel QSqlRelationalTableModel QSortFilterProxyModel
Commonly Used Qt Model Classes
QGraphicsView – a view for fast structured 2D graphics Graphics items known as QGraphicItems are placed in
a scene known as QGrahpicsScene A scene is then displayed in one or more views
(QGraphicViews) Graphic items can be
lines, rectangesl polygons, pixmaps, ellipses, text, SVG drawings, widgets or any customizable item you can think of
moved, scaled, rotated
Graphics View
QGraphicsItems are lightweight compared to QWidget This allows for thousands of these guys to exist while not
taking a hit on performance or memory QGraphItems can be arbitrarily transformed
(QTransform) Support for high quality zooming for example
Graphics Items have there own internal event system that is slightly different than the regular QEvent system
Widgets can be embedded into a graphics scene by using the QGraphicsProxyWidget
Graphics Items
#include <QtGui>
int main(int argc, char **argv) {QApplication app(argc, argv);QGraphicsScene scn;
QGraphicsEllipseItem ellipse(-10, -10, 120, 50);scn.addItem(&ellipse);
QGraphicsTextItem text(“Hello World”);scn.addItem(&text);
QGraphicsView view(&scn);view.show();return app.exec():
}
Hello World Graphics View Example
http://qt-project.org/videos/watch/programming_with_qt_qgraphicsview_by_kdab
http://qt-project.org/videos/watch/programming_with_qt_qgraphicsview_by_ics
For More About QGraphicViewCheck these Videos:
Qt supports Unicode via QString Support for Right-to-Left (Chinese) Read/Write files in different codecs Layout system can be internationalized Qt Linguist applications allows apps to be
translated easily
Internationalization
“Translating Qt Applications” – Benjamin Poulainhttp://qt-project.org/videos/watch/translating_qt_applications
To learn more on Internationalization see
Shared memory TCP/UDP Sockets (QSocket) HTTP/FTP protocol support D-Bus
Interprocess Communication (IPC)
Introduced in Qt 4.6 and part of QtCore module Originated from Qt-SCXML research project SMF provides the means to create heirarchical
finite state machines (HFSMs) SMF also provides an “interpreter” for executing
HFSMs Helps to reduce spaghetti code by
By making if statements implicit since state is implicit Producing clear control flow
Qt State Machine Framework (SMF)
State Machine Framework http://
www.slideshare.net/qtbynokia/qt-state-machine-framework -Slides
http://qt-project.org/videos/watch/state_machine_framework - Video
For more learning on Qt State Machines
Qt supports test driven development (TDD) Using QTestLib, Qt developers can do unit tests Qt supports
Basic Unit Testing Data Driven Testing Cross-Platform and Cross-Compiler Unit Tests Stand alone unit tests Memory Debugging Integrations
Unit Testing
QVERIFY Evaluates complex expressions
QCOMPARE Compares two values using the respective
object comparison operator
Qt Unit Test Macros
class QStringTest : public QObject {Q_OBJECT
private slots:void toUpper(){
QString str(“hello world”);QCOMPARE(str.toUpper(),
Qstring(“HELLO WORLD”));}
};
Hello World Unit Test Example
Allows for separation of logic and data Improved readability Easily extendable Reduction of copy and pasting of code in test
code Ease in testing the border cases of the
application
Benefits of Data Driven Tests
QtTestLib offers non-native mouse and keyboard simulation support for QWidgets
Very basic support for replay eventa 3rd party tools such as Squish and KD
Executer
Coded UI Test Support
Squish - http://qt-project.org/wiki/Category:Tools::Squish
Unit Testing in Qt Applications by Harald Fernengel http://qt-project.org/videos/watch/unit_testing_in_qt_applications
Learn more about Qt Unit Testing
Qt provides QBENCHMARK to measure code QBENCHMARK measures code based on
Walltime (default) CPU Tick Count (-tickcounter) Valgrind/Callgrind (-callgrind) Event counter (-eventcounter)
Performance
TOC was developed by Eliyahu M. Goldratt Basically TOC is a theory which says that given
a complex system, there is usually one aspect of that system that will limits it ability to achieve its goal or optimal functioning. Before an achievement of any significant improvement of the system can be achieved, the constraint or bottleneck must be first identified and resolved Reduce Bottlenecks improve Performance
Theory of Constraints
Choose the right container Utilize implicit data sharing efficiently
ExampleObject obj0;Object obj1, obj2, obj3 = obj0 Here data is only copied if some other guy modifies it since
Object 1 will have deep copy of object ObjectData and Object 2 and Object 3 will only have shallow copies
Avoid deep-copy, its expensive Pass objects around as const references Only use const operators and functions if possible
Avoid bottlenecks
Qt Optimization Techniques
Optimizing Performance in Qt Based Applications - Bjørn Erik Nilsen http://www.slideshare.net/qtbynokia/optimizing-performance-in-qtbased-applications
To learn more about Optimizing your Qt Apps check
Thanks