introduction to qt build great apps using qt jeff alstadt
TRANSCRIPT
![Page 1: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/1.jpg)
Introduction to QtBuild Great Apps Using Qt
Jeff Alstadt
![Page 2: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/2.jpg)
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
![Page 3: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/3.jpg)
Today we are talking about
![Page 4: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/4.jpg)
This Is Qt 5
![Page 5: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/5.jpg)
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?
![Page 6: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/6.jpg)
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
![Page 7: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/7.jpg)
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
![Page 8: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/8.jpg)
So what does the Qt ecosystem look like
![Page 9: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/9.jpg)
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?
![Page 10: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/10.jpg)
#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
![Page 11: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/11.jpg)
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…
![Page 12: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/12.jpg)
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
![Page 13: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/13.jpg)
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
![Page 14: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/14.jpg)
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
![Page 15: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/15.jpg)
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
![Page 16: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/16.jpg)
The Qt Lighthouse project was an initiative to get Qt running on the iOS platforms.
Qt Meets iOS
![Page 17: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/17.jpg)
Qt Overall Architecture
![Page 18: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/18.jpg)
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
![Page 19: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/19.jpg)
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
![Page 20: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/20.jpg)
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
![Page 21: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/21.jpg)
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
![Page 22: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/22.jpg)
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
![Page 23: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/23.jpg)
Signal Slot Code Example
![Page 24: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/24.jpg)
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
![Page 25: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/25.jpg)
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
![Page 26: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/26.jpg)
QResizeEvent (Window Resizing) QPaintEvent (Window Repainting) QMouseEvent (Mouse Input) QKeyEvent (Keyboard Input) QCloseEvent (Window close)
Common Qt Events
![Page 27: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/27.jpg)
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
![Page 28: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/28.jpg)
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
![Page 29: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/29.jpg)
QStringListModel QStandardItemModel QDirModel QSqlQueryModel QSqlTableModel QSqlRelationalTableModel QSortFilterProxyModel
Commonly Used Qt Model Classes
![Page 30: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/30.jpg)
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
![Page 31: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/31.jpg)
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
![Page 32: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/32.jpg)
#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
![Page 33: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/33.jpg)
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:
![Page 34: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/34.jpg)
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
![Page 35: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/35.jpg)
“Translating Qt Applications” – Benjamin Poulainhttp://qt-project.org/videos/watch/translating_qt_applications
To learn more on Internationalization see
![Page 36: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/36.jpg)
Shared memory TCP/UDP Sockets (QSocket) HTTP/FTP protocol support D-Bus
Interprocess Communication (IPC)
![Page 37: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/37.jpg)
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)
![Page 38: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/38.jpg)
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
![Page 39: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/39.jpg)
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
![Page 40: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/40.jpg)
QVERIFY Evaluates complex expressions
QCOMPARE Compares two values using the respective
object comparison operator
Qt Unit Test Macros
![Page 41: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/41.jpg)
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
![Page 42: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/42.jpg)
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
![Page 43: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/43.jpg)
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
![Page 44: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/44.jpg)
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
![Page 45: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/45.jpg)
Qt provides QBENCHMARK to measure code QBENCHMARK measures code based on
Walltime (default) CPU Tick Count (-tickcounter) Valgrind/Callgrind (-callgrind) Event counter (-eventcounter)
Performance
![Page 46: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/46.jpg)
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
![Page 47: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/47.jpg)
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
![Page 48: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/48.jpg)
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
![Page 49: Introduction to Qt Build Great Apps Using Qt Jeff Alstadt](https://reader031.vdocuments.mx/reader031/viewer/2022032015/56649d0b5503460f949deeaf/html5/thumbnails/49.jpg)
Thanks