Qt Essentials - Fundamentals of Qt Module
Training Course
Visit us at http://qt.digia.com
Produced by Digia Plc.
Material based on Qt 5.0, created on September 27, 2012
Digia Plc.
Module: Fundamentals of Qt
The Story of Qt
Developing a Hello World Application
Hello World using Qt Creator
Practical Tips for Developers
2/31
Fundamentals of Qt
Module Learning Objectives
Learn ...
... about the history of Qt
... about Qt's ecosystem
... a high-level overview of Qt
... how to create rst hello world program
... build and run a program cross platform
... to use Qt Creator IDE
... some practical tips for developing with Qt
3/31
Fundamentals of Qt
Module: Fundamentals of Qt
The Story of Qt
Developing a Hello World Application
Hello World using Qt Creator
Practical Tips for Developers
The Story of Qt
4/31
Fundamentals of Qt
Meet Qt
Qt Development Frameworks founded in 1994
Trolltech acquired by Nokia in 2008
Qt Commercial business acquired by Digia in 2011
Qt business acquired by Digia from Nokia in 2012
Trusted by over 6,500 companies worldwide
Qt: a cross-platform application and UI framework
For desktop, mobile and embedded development
Used by more than 350,000 commercial and open source developers
Backed by Qt consulting, support and training
See
Qt Services
.
The Story of Qt
5/31
Fundamentals of Qt
Qt is used everywhere
The Story of Qt
6/31
Fundamentals of Qt
The Qt virtuous cycle
.See Qt Licensing
The Story of Qt
7/31
Fundamentals of Qt
Why Qt
Write code once to target multiple platforms
Produce compact, high-performance applications
Focus on innovation, not infrastructure coding
Choose the license that ts you
Commercial, LGPL or GPL
Count on professional services, support and training
Take part in an active Qt ecosystem
.
.15 years of customer success and community growth
The Story of Qt
8/31
Fundamentals of Qt
Why Qt Commercial
Improved development tools for increased productivity and tangible
cost savings
Qt Commercial SDK
All Qt Commercial libraries and tools
Additional tools and components
Qt Creator Embedded Target
Deploy directly to embedded Linux target
RTOS toolchain integration
Visual Studio Add-On
The Story of Qt
9/31
Fundamentals of Qt
Qt5
Awesome graphics capabilities
OpenGL as a standard feature of user interfaces
Shader-based graphics effects in QtQuick 2
New modular structure
Qt Essential modules available on all platforms
Add-on modules provide additional or platform-specic functionality
Developer productivity and exibility
More web-like development with QtQuick 2, V8 JvaScript engine, and Qt
JSON DB
Cross-platform portability
Qt Platform Abstraction (QPA) replaces QWS and platform ports
The Story of Qt
10/31
Fundamentals of Qt
Qt5 Modules
The Story of Qt
11/31
Fundamentals of Qt
Qt5 Highlights
QtCore
JSON parser and speed optimized binary format for JSON
Compile time checked signal/slot connection syntax
New plugin loader - no need to load plugnis to see what they implement
Re-written QMap for optimized performance
QtGui
Printing and widgets moved into their own libs
Platform ports based on QPA
QApplication split into QApplication and QGuiApplication
QWindow to reprsent a top-level surface
Touch improvements (device capabilities like pressure)
QtQuick 2
Support for touch gestures
Locale API to QML
Particle system
RTL support
The Story of Qt
12/31
Fundamentals of Qt
Qt Demo
Let's have a look at the QtDemo Application
Comes with every Qt installation
Technology
Painting
Widgets
Widgets
Graphics View
OpenGL
WebKit
The Story of Qt
Demo
Demonstrations/Path Stroking
Demonstrations/Books
Demonstrations/TextEdit
Demonstrations/40.000 Chips
Demonstrations/Boxes
Demonstrations/Browser
13/31
Fundamentals of Qt
Module: Fundamentals of Qt
The Story of Qt
Developing a Hello World Application
Hello World using Qt Creator
Practical Tips for Developers
Developing a Hello World Application
14/31
Fundamentals of Qt
``Hello World'' in Qt
// main.cpp
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton button("Hello world");
button.show();
return app.exec();
}
Program consists of
main.cpp - application code
helloworld.pro - project le
Developing a Hello World Application
.Demo fundamentals/ex-helloworld
15/31
Fundamentals of Qt
Project File - helloworld.pro
helloworld.pro le
lists source and header les
provides project conguration
# File: helloworld.pro
SOURCES
= main.cpp
HEADERS +=
QT
# No headers used
= core gui widgets
Assignment to variables
Possible operators =, +=, -=
.See qmake tutorial Documentation
Developing a Hello World Application
16/31
Fundamentals of Qt
Using qmake
qmake tool
Creates cross-platform make-les
Build project using qmake
cd helloworld
qmake helloworld.pro # creates Makefile
make
# compiles and links application
./helloworld
# executes application
Tip: qmake -project
Creates default project le based on directory content
See
qmake Manual Documentation
.
Qt Creator does it all for you
Developing a Hello World Application
17/31
Fundamentals of Qt
Module: Fundamentals of Qt
The Story of Qt
Developing a Hello World Application
Hello World using Qt Creator
Practical Tips for Developers
Hello World using Qt Creator
18/31
Fundamentals of Qt
QtCreator IDE
Advanced C++ code editor
Integrated GUI layout and forms designer
Project and build management tools
Integrated, context-sensitive help system
Visual debugger
Rapid code navigation tools
Supports
multiple
platforms
Hello World using Qt Creator
19/31
Fundamentals of Qt
Overview of Qt Creator Components
Hello World using Qt Creator
20/31
Fundamentals of Qt
Finding Code -Locator
Click on Locator or press Ctrl+K (Mac OS X: Cmd+K)
Type in the le name
Press Return
Locator Prexes
: <class name> - Go to a symbol denition
l <line number> - Go to a line in the current document
? <help topic> - Go to a help topic
o <open document> - Go to an opened document
Hello World using Qt Creator
21/31
Fundamentals of Qt
Debugging an Application
Debug > Start Debugging (or F5)
Hello World using Qt Creator
22/31
Fundamentals of Qt
Qt Creator Demo "Hello World"
What we'll show:
Creation
of an empty Qt project
Adding
the main.cpp source le
Writing of
the Qt Hello World Code
Showing Locator Features
Running the application
Debugging the application
Looking up the text property of our button
Hello World using Qt Creator
23/31
Fundamentals of Qt
Module: Fundamentals of Qt
The Story of Qt
Developing a Hello World Application
Hello World using Qt Creator
Practical Tips for Developers
Practical Tips for Developers
24/31
Fundamentals of Qt
How much C++ do you need to know?
Objects and classes
Declaring a class, inheritance, calling member functions etc.
Polymorphism
That is virtual methods
Operator overloading
Templates
For the container classes only
No ...
... RTTI
... sophisticated templates
... exceptions thrown
...
Practical Tips for Developers
25/31
Fundamentals of Qt
Qt Documentation
Reference Documentation
All classes documented
Contains tons of examples
Collection of Howto's and Overviews
A set of Tutorials for Learners
Practical Tips for Developers
26/31
Fundamentals of Qt
Finding the Answers
Documentation in Qt Assistant (or QtCreator)
Qt's examples: $QTDIR/examples
Qt developer network: http://qt-project.org/
Qt Centre Forum: http://www.qtcentre.org/
KDE project source code
http://lxr.kde.org/ (cross-referenced).
Online communities
http://qt-project.org/wiki/OnlineCommunities
.
Use the source!
.
Qt's source code is easy to read, and can answer questions the reference
manual
cannot answer!
.
Practical Tips for Developers
27/31
Fundamentals of Qt
Modules and Include les
Qt Modules
QtCore, QtGui, QtWidgets, QtXml, QtSql, QtNetwork, QtTest ...
.See Qt Modules Documentation
Enable Qt Module in qmake .pro le:
QT += network
Default: qmake projects use QtCore and QtGui
Any Qt class has a header le.
#include <QLabel>
#include <QtWidgets/QLabel>
Any Qt Module has a header le.
#include <QtGui>
Practical Tips for Developers
28/31
Fundamentals of Qt
Includes and Compilation Time
Module includes
#include <QtGui>
Precompiled header and the compiler
If not supported may add extra compile time
If supported may speed up compilation
Supported on: Windows, Mac OS X, Unix
See
qmake precompiled headers Documentation
.
Class includes
#include <QLabel>
Reduce compilation time
Use class includes (#include <QLabel>)
Forward declarations (class QLabel;)
Place module includes before other includes.
Practical Tips for Developers
29/31
Fundamentals of Qt
Questions And Answers
What is Qt?
Which code lines do you need for a minimal Qt application?
What is a .pro le?
What is qmake, and when is it a good idea to use it?
What is a Qt module and how to enable it in your project?
How can you include a QLabel from the QtGui module?
Name places where you can nd answers about Qt problems
Practical Tips for Developers
30/31
Fundamentals of Qt
Questions And Answers
What is Qt?
Which code lines do you need for a minimal Qt application?
What is a .pro le?
What is qmake, and when is it a good idea to use it?
What is a Qt module and how to enable it in your project?
How can you include a QLabel from the QtGui module?
Name places where you can nd answers about Qt problems
Practical Tips for Developers
30/31
Fundamentals of Qt
Questions And Answers
What is Qt?
Which code lines do you need for a minimal Qt application?
What is a .pro le?
What is qmake, and when is it a good idea to use it?
What is a Qt module and how to enable it in your project?
How can you include a QLabel from the QtGui module?
Name places where you can nd answers about Qt problems
Practical Tips for Developers
30/31
Fundamentals of Qt
Questions And Answers
What is Qt?
Which code lines do you need for a minimal Qt application?
What is a .pro le?
What is qmake, and when is it a good idea to use it?
What is a Qt module and how to enable it in your project?
How can you include a QLabel from the QtGui module?
Name places where you can nd answers about Qt problems
Practical Tips for Developers
30/31
Fundamentals of Qt
Questions And Answers
What is Qt?
Which code lines do you need for a minimal Qt application?
What is a .pro le?
What is qmake, and when is it a good idea to use it?
What is a Qt module and how to enable it in your project?
How can you include a QLabel from the QtGui module?
Name places where you can nd answers about Qt problems
Practical Tips for Developers
30/31
Fundamentals of Qt
Questions And Answers
What is Qt?
Which code lines do you need for a minimal Qt application?
What is a .pro le?
What is qmake, and when is it a good idea to use it?
What is a Qt module and how to enable it in your project?
How can you include a QLabel from the QtGui module?
Name places where you can nd answers about Qt problems
Practical Tips for Developers
30/31
Fundamentals of Qt
Questions And Answers
What is Qt?
Which code lines do you need for a minimal Qt application?
What is a .pro le?
What is qmake, and when is it a good idea to use it?
What is a Qt module and how to enable it in your project?
How can you include a QLabel from the QtGui module?
Name places where you can nd answers about Qt problems
Practical Tips for Developers
30/31
Fundamentals of Qt
Digia Plc.
Digia, Qt and the Digia and Qt logos are the registered trademarks of
Digia Plc. in Finland and other countries worldwide.
Practical Tips for Developers
31/31
Fundamentals of Qt