SlideShare a Scribd company logo
1 of 106
Qt5

Qt 5 project: http://qt-project.org/
Tools: http://qt-project.org/downloads
Docs: http://qt-project.org/doc/
Qt Commercial: http://qt.digia.com/
Lectures by Juha Peltomäki
5 Framework
●

Qt5 – Cross Platform Framework
–

Qt5: http://qt-project.org/doc/

–

Old Qt4: http://doc.qt.nokia.com/
A cross-platform application development
framework
●

●

●

●

Using Qt, you can write applications and user interfaces
once, and deploy them across many OS.

In June 2008 Nokia acquired Trolltech ASA to
enable the acceleration of their cross-platform
software strategy for mobile devices and desktop
applications.

In August 2012 Digia announced its plans to acquire the
Qt technology and business from Nokia.
December 19, 2012 — Digia has announced the launch of
Qt 5.
–

”Qt 5 delivers a step function increase in performance,
functionality and ease of use and will be the platform on
which full Android and iOS support will be delivered
during the coming year."
Qt5 overview
●

●

cross-platform, graphical, application
development toolkit
run applications on Windows, Mac OS X,
Linux, and different embedded/mobile OSs
–

●

embedded Linux like Android, iOS, Blackperry,
also some RTOS LInux OS like QNX are
supported

licensed under a professional (commercial,
closed source) and GPL/ LGPL (open source)
Qt5 Tools
●

Qt Creator as a main IDE tools
–

●

Qt Creator should be the first choice for Qt
beginners who want to get up and running quickly
with Qt framework

Qt Creator includes
–
–

Qt Linquist for localization

–
●

Qt Designer for easy UI designing and building
qmake to build apps to different target platforms

Qt5 development tools:
–

http://qt-project.org/doc/qt-5.1/qtdoc/topics-app-development.html
Qt libraries
●

GUI and Widget libraries

●

Networking

●

XML

●

SQL

●

Container classes

●

Multi-threading

●

Animation

●

Scripting

●

QtQuick / QML
Qt Creator
●

Qt Creator - Originally Published at Oct '08
–

a lightweight IDE

–

supports developing for different platforms

–

open and easily extendable

–

Context-sensitive help

–

Creating, editing and navigating code

–

supports the GNU compiler (gcc) and debugger

–

supports qmake build system
Qt Designer
●

GUI tools for rapid software development

●

Separate easily UI from model classes
–

Much easier than manual UI coding

–

UI saved in XML files

–

Support for signals and slots mechanism

–

Support QML
Qt programming environment
●
●

●

●

Originally C++ based Framework
Qt5 Supports also QML with JavaScript with
support to C++ "backend" components
supports single-source cross-platform
development on Windows, Mac and Linux
desktop and different embedded and mobile
platforms (Blackberry 10, Android etc.)
KDE Desktop environment is based on Qt
Framework
Links for Learning Qt
●

●

Book Online: ”The Art of Building Qt
Applications”:
http://pyqt-doc-cn.googlecode.com/files/The_Art_of
If you want to program purely in Qt/C++ and
design your interfaces in code without the aid of
any design tools, take a look at the Qt Tutorials.
Qt5 - Getting started
●

You can select 2 different approach to develop
your Qt5 applications

●

These are

●

Qt5 Widgets – C++ based, traditional way

●

●

●

QML, declarative UI language with JavaScript
support
http://qt-project.org/doc/qt-5.1/qtdoc/gettingstarted.html
Qt Widgets
●

The Qt Widgets Module provides a set of UI
elements to create classic desktop-style user
interfaces
●

–

http://qt-project.org/doc/qt-5.1/qtwidgets/qtwidgets-index.html

QWidget class provides the basic capability to
render to the screen, and to handle user input
events.
Qt Quick (QML)
●

QtQuick and QML (Declarative UI language)
–

QtDeclarative creates a JavaScript runtime that
QML runs with a Qt/C++ application
●

●

●

can call C++ from QML and visa versa

QML is easy enough for designers also, so UI
can be prototyped very quickly with QML
You can separate backend code from UI code
easily so it enforces to use Model/View
architecture in your application
Qt Core

Some Qt Core Source material:
●

●

●

●

●

●

Classes:
http://qt-project.org/doc/qt-5.1/qtdoc/qtmodules.html
Qt Core:
http://qt-project.org/doc/qt-5.1/qtcore/qtcore-index.html
Object model:
http://qt-project.org/doc/qt-5.1/qtcore/object.html
Object trees:
http://qt-project.org/doc/qt-5.1/qtcore/objecttrees.html
MOC:
http://qt-project.org/doc/qt-5.1/qtcore/metaobjects.html
QtCore library
Basic data types are supported
●
●

●

●
●

Qt supports C++ basic types and basic classes
Qt's own class types are used (QString,
QVector etc.) in most cases
basic data collection structures (vector, list,
maps) are defined by Qt
Even the basic data types are predefined by Qt
Well-defined parent, child relationship between
components
Qt is dynamic
●

Standard C++ has efficient run-time support but
very static model
●

Qt's Object model adds more dynamic model for
creating GUI and possible to add dynamic
properties using moc compiler
Qt's Object model
●

●

●
●

flexibility of Qt is basicly implemented in the Qt's
Object Model.
Qt features are implemented based on QObject
using standard C++.
Qt has it's own Meta-Object Compiler (moc).
C++/GUI programming needs more flexibility and
Qt provides it.
Qt's features
●

●

hierarchical object trees that organize object
ownership in a natural way
efficient object communication (signals and
slots)

●

dynamic properties of Object

●

powerful events and event filters
Qt's features
●

guarded pointer (QPointer) is automatically set
to 0 when the referenced object is destroyed
●

●

●

normal C++ pointers become "dangling
pointers" in such cases

dynamic cast (qobject_cast) that works across
library boundaries with every class inherit from
QObject

interval driven timers that make it possible to
elegantly integrate many tasks in an eventdriven GUI
QObject – the base class of Qt's
Object hierarchy
●

Has Unique name (QObject::objectName())

●

has a location in an object hierarchy

●

●

can be connected to any other Qt Objects to
emit/receive signals

new dynamic properties can be added to it at
runtime
–

Note! QObject and all subclasses of QObject
have their copy constructor and assignment
operator disabled.
Qt data types
●

●

QtGlobal header file declares several type definitions that guarantee a
specified bit-size on all platforms supported by Qt for various basic types, for
example qint8 which is a signed char guaranteed to be 8-bit on all platforms
supported by Qt.
Source: http://qt-project.org/doc/qt-5.1/qtcore/qtglobal.html
QtCore Module
●

●

●

The QtCore module contains core functionality
to create business logic
Some of most important and useful classes are
listed below:
QtCore classes
●

●
●

QMetaObject - Contains meta-information about
Qt objects
QObject - The base class of all Qt objects
QVariant - Acts like a union for the most common
Qt data types
QtCore Module continues
●

QCoreApplication - Event loop for console Qt
applications. For UI applications see QApplication
class from QtGui module
–

●

●

Event loop is started with QCoreApplication::exec
and uses exit() to exit from the main event loop.

QEvent - is The base class of all event classes.
Event objects contain event parameters
QMetaObject class contains meta-information
●

Also there is QtConcurrent namespace high-level
APIs that make it possible to write multi-threaded
programs more easily.
QtCore - container classes
●

●

●
●

●

QHash - Template class that provides a hash-tablebased dictionary
QLinkedList lists

Template class that provides linked

QList - Template class that provides lists
QMap - Template class that provides a skip-listbased dictionary
QMultiHash - Convenience QHash subclass that
provides multi-valued hashes
QtCore container classes
●

●

●
●

●

QMultiMap - Convenience QMap subclass that
provides multi-valued maps
QSet - Template class that provides a hash-tablebased set
QStack - Template class that provides a stack
QVector - Template class that provides a dynamic
array
QVectorIterator - Java-style const iterator for
QVector and QStack
QtCore char/string classes
●

●
●

●
●

●

QString - Unicode character string (stores a string of
16-bit QChars)
QStringList - List of Unicode strings
QByteArray – store raw bytes or traditional 8-bits
strings (const char *)
QChar - 16-bit Unicode character
QLatin1String - wrapper for Latin-1/ASCII
encoded 8-bit string (see QString::toLocal8Bit ())
QRegExp - regular expression support for QStrings
QtCore - multithread classes
●

QRunnable - base class for all runnable objects

●

QThread is for Platform-independent threads

●

QThreadPool manages a collection of Qthreads

●

Note! QtConcurrent namespace provides high-level
APIs that make it possible to write multi-threaded
programs without using low-level threading
(introduced in Qt 4.4.)
QtCore utility classes
●

QDate - Date functions

●

QDateTime -

●

QTime - Clock time functions

●

QTimer - Repetitive and single-shot timers

●

Date and time functions

QPoint - Defines a point in the plane using
integer precision
QtCore model classes
●

●

●

QAbstractItemModel The abstract interface for item
model classes
QAbstractListModel Abstract model that can be
subclassed to create one-dimensional list models
QAbstractTableModelAbstract model that can be
subclassed to create table models
Qt Core file/XML classes
●

●

●

QtextStream - Convenient interface for reading and
writing text
QDir - Access to directory structures and their
contents
QFile - Interface for reading from and writing to
files

●

QXmlStreamReader - Fast XML streaming API

●

QXmlStreamWriter - streaming writer for XML
JSON
●

Starting from Qt 5.0 the Qt Core provides a set
of classes to enable parsing and generating
JSON documents.
Qt GUI and Widgets
●

Qt tutorial:
–

–

●

●

http://qt-project.org/doc/qtcreator-2.8/creator-tutorials.html

http://qt-project.org/doc/qt-5.1/qtdoc/topics-ui.html

Qt UI
Qt GUI
–

●

Qt Widgets
–

●

http://qt-project.org/doc/qt-5.1/qtwidgets/qtwidgets-index.html

Qt Graphics
–

●

http://qt-project.org/doc/qt-5.1/qtgui/qtgui-index.html

http://qt-project.org/doc/qt-5.1/qtdoc/topics-graphic
QApplication and Event loop
●

●

QApplication class manages the GUI application's
control flow. It's has no graphical presentation but
it's used in programs which has an graphical user
interface.
QApplication manages application's control flow
and main setting:
QApplication
●

●

●

handles the application's initialization and
finalization
contains the main event loop where all events
from the event sources are processed
Setting includes mouse's wheel or double click
settings and font setting and setting UI's
look&feel style
QApplication
●
●

●

provides session management.
handles most system-wide and application-wide
settings (like application font or style)
For any Qt GUI application there is always one
QApplication object.
–

If you don't have GUI then use QCoreApplication
instead
QtWidgets
●

The QtWidgets module extends QtCore with
GUI functionality
–

●

The core class in QtWidgets module is The
QWidget class which is the base class of all
UI objects (like QMainWindow or QDialog).

Note! When you use Qt Creator or Qt designer
to create your UI you save it to XML format
–

Forms in .ui (XML) file format are compiled
during build process into C++ header files by
UIC compiler.

–

If the form is mycomponent.ui then UIC
generates ui_mycomponent.h.
Qt GUI before Qt 5
●

●

Prior to Qt 5.0, the Qt GUI module was the monolithic
container for all things relating to graphical user
interfaces in Qt, and included the Qt widget set, the
item views, the graphics view framework and also
printing. Starting Qt 5, these classes have been
moved to the Qt Widgets module. Printing has been
moved to the Qt Print Support module. Please note
that these modules can be excluded from a Qt
installation.
http://qt-project.org/doc/qt-5.1/qtgui/qtgui-index.html
Qt GUI in Qt 5
●

●

●

QWidget and all derived classes are a core part
of Qt 5 on the Desktop.
In Qt 5 you can still continue writing apps in
exactly the same way as you have been doing
with Qt 4.x.
Qt5 is mainly source compatibility with Qt 4.x
Qt 5 Widgets
Layout
●

●

If some graphical Qt widget should be
displayed it need some form of layout to put
into the form.
All Qt's layouts are derived from the base
class, QLayout.
–

Layouts are geometry managers that fit into
the composition hierarchy of a graphical
interface.
Qt Layouts
●

There are specific layout classes in Qt:
–

QHBoxLayout, QVBoxLayout – lines up
widgets horizontally or vertically

–

QGridLayout – lays out widgets in grid

–

QStackedLayout - a stack of widgets
Qt Layouts
QMainWindow
●

●

When you want to create a bigger application,
which handles many kind of input data and has
lot of operation you should use main window to
create your application.
In the most Qt applications has a single
QMainWindow.
●

●

It can include many UI components (Qt
widgets).
It is the parent of all other widgets that are in
the main window.
QMainWindow
●

It has some common features to all kind of
desktop applications:
●
●

Menu bar

●

Status bar

●

Toolbars

●

●

A central widget

Dock regions

It's common practice to derive QMainWindow
class to create own main window class.
Qt widgets
●

All Qt's widgets are derived from QWidget base
class.
–

QWidget is a base class for all widgets in Qt

–

creating a new widget you have to subclass
the QWidget class.

–

it has a visual representation on the screen

–

It is a reusable building block for creating UI

–

You can form any kind of widget, but also
have to implements many methods

–

internal states, all repainting and size hinting
are managed by own widget class
More of QWidget
●

●

●

It's a QObject, and thus can have parents,
signals, slots, and managed children
is a QPaintDevice, the base class of all widgets
that can be draw on the screen
can handle
–

signals responsing

–

event send by other widgets,

–

mouse, keyboard, other pointer devices

–

processes etc.
Qt widget hierarchy
QWidget methods
●

Some of most important methods of QWidget in
example:
●

basic things: constructor, sizeHint etc.

●

Painting: The paintEvent

●

●

Mouse interaction: mousePressEvent,
mouseMoveEvent, mouseReleaseEvent.
Timing: The QTimer object is connected to the
timeout slot
Classes used in UI
●

These classes doesn't have graphical
presentation but these are commonly used with
Qt widgets
●

Qt Data types: QPoint and QSize .

●

Controller classes: QApplication and QAction.

●

Layouts: QHBoxLayout, QVBoxLayout, QGridLayout,
etc.
Non-visual classes
●

Models: The QAbstractItemModel and its derived
classes QAbstractListModel and
QAbstractTableModel are part of Qt's
Model/View framework,
●

●

These models used as base classes for classes that
represent data for a corresponding UI components
like QListView, QtreeView, or QtableView.

Database models: These are used with
QTableView for using databases:
QSqlTableModel and QSqlRelationalModel.
Qt widgets categories
●

●

●

Button widgets (etc.QPushButton,
QRadioButton)
Input widgets (etc.QLineEdit, QTextEdit,
QDateEdit, QSlider )
Display widgets (QLabel, QProgressBar,
QPixmap etc).
Qt Widgets categories II
●

●

●

Container widgets (QMainWindow, QFrame,
QToolBar, QTabWidget ec.)
Dialog widgets (QFileDialog, QInputDialog,
QErrorMessage etc.)
View widget (QListView, QTreeView,
QTableView etc.)
GUI classes I
●

●

●

●

QAbstractItemModel
model classes

- abstract interface for item

QAbstractItemView - basic functionality for item
view classes
QAbstractListModel - Abstract model that can be
subclassed to create one-dimensional list models
QAbstractTableModel -Abstract model that can be
subclassed to create table models
GUI classes II
●

●

●

●

QAction - Abstract user interface action that can be
inserted into widgets
QActionEvent - Event that is generated when a
QAction is added, removed, or changed
QApplication - Manages the GUI application's
control flow (event loop) and main settings
QBoxLayout - Lines up child widgets horizontally
or vertically

●

QCheckBox - Checkbox

●

QComboBox - Combined button and popup list
Qt GUI classes III
●

QCoreApplication
applications

- Event loop for console Qt

●

QDial - Rounded range control

●

QDialog - The base class of dialog windows

●

QEvent - The base class of all event classes.
●

●

●

objects contain event parameters

QFileDialog - Dialog that allow users to select
files/dirs
QFormLayout - Manages forms of input widgets
and their associated labels
Qt GUI classes IV
●

QGridLayout - Lays out widgets in a grid

●

QHBoxLayout - Lines up widgets horizontally

●

●
●

●

QImage - Hardware-independent image
representation
QInputDialog - Simple input dialog
QInputEvent - The base class for events that
describe user input
QIntValidator - Validator for integer within a
specified range
Qt Gui classes V
●
●

QKeyEvent - Describes a key event
QLCDNumber - Displays a number with LCD-look
digits

●

QLabel - Text or image display

●

QLayout - The base class of geometry managers

●

QListView - List view onto a model

●

QListWidget - Item-based list widget

●

QMatrix - 2D transformations of a coordinate
system
Qt GUI classes VI
●

QMenu

●

QMenuBar -

●

QMenuItem - an menu item

●

QMessageBox - Simple Modal dialog

●

QMouseEvent -

●

- Menu widget for use in menus
menu bar

parameters describe a mouse event

QPaintDevice - The base class of objects that can be
painted
Qt GUI classes VII
●

●

●

QPaintEvent - Contains event parameters for paint
events
QPainter - Performs low-level painting on widgets
and other paint devices
QPicture - Paint device that records and replays
QPainter commands

●

QPixmap - Off-screen image representation

●

QPushButton - Command button

●

QRadioButton - Radio button with a text label
Qt GUI classes VIII
●

QScrollArea - Scrolling view onto another widget

●

QSpinBox

●

●
●

●

- Spin box widget

QSplashScreen - Splash screen that can be shown
during application startup
QSplitter - Implements a splitter widget
QStyle - Abstract base class that encapsulates the
look and feel of a GUI
QStyleFactory - Creates QStyle objects
Qt GUI classes IX
●
●

●

●
●

●

QTabBar - Tab bar, e.g. for use in tabbed dialogs
QTableView- Default model/view implementation of
a table view
QTableWidget - Item-based table view with a
default model
QTextBrowser - Rich text browser
QTextDocument - Holds formatted text that can be
viewed and edited using a QTextEdit
QTextEdit -Widget that is used to edit/display text
Qt GUI classes X
●

QToolBar - Movable panel that contains a set of
controls

●

QToolTip - balloon help

●

QTranslator - Internationalization support

●

●

●

QTreeView - Default model/view implementation of a
tree view
QTreeWidget - Tree view that uses a predefined tree
model
QVBoxLayout - Lines up widgets vertically
Qt GUI programming features
●

Signals and slots

●

Moc

●

Uic

●

Qt Events
GUI programming with Qt
●

●

Qt's GUI library is very professional level
framework
This historically the most important reason why
Qt has been so successful C++ framework for
creating application.
–

KDE desktop environment has used Qt since
1996
●

http://www.kde.org/announcements/announcement.p
Signals and slots
●

In GUI programming, we want objects of any
kind to be able to communicate with one
another.
–

if a user clicks a Close button, we probably
want the window's close() function to be
called.
Signals and Slots
●

In Qt, we have an alternative to the callback
technique: signals and slots.
–

It is slightly different way of thinking GUI
events and event handling

–

C++ Macros and a preprocessor makes it
feel as if the signal-slot syntax was part of
standard C++

–

All classes that inherit from QOobject or it's
subclasses can contain signals and slots.
Emitting signals
●

Signals are emitted when QObject's state is
changing
–

–
●

doesn't need to care if there is any Object to
handle signals
object is like a reusable software component.

A signal is emitted when a particular event
occurs.
–

It's possible also to subclass widget and add
our own signals to them.
Slot
●

A slot is a function that is called in response to
a particular signal.
–

Qt's widgets have many pre-defined slots, but
it is also possible to subclass widgets and add
your own slots.
●

Also QML supports signal-slot mechanism
Q_OBJECT macro
●

All classes that contain signals or slots must
mention Q_OBJECT macro at the top of their
declaration.
–

must also derive (directly or indirectly) from
QObject
QObject::connect
●

connect function is a static function of QObject.
–

It creates connection between two QObject.

bool QObject::connect ( const QObject * sender, const char * signal, const QObject *
receiver, const char * method, Qt::ConnectionType type = Qt::AutoConnection )
QObject::connect(scrollBar, SIGNAL(valueChanged(int)), label,

●

A signal-slot connection is removed when either
of the objects involved are destroyed.
–

●

SLOT(setNum(int)));

It's possible to disconnect connection with
disconnect() method

New signal/slot syntax in Qt5:
http://qt-project.org/wiki/New_Signal_Slot_Syntax
Example of signals and slot
●

In the next example are used signals and
slots mechanism to connect the QSlider's
valueChanged() signal to the QLCDNumber's
display() slot.
–

Signal is emitted in event handler method
●

MousePressEvent can receive mouse press
events for the widget. Other mouse event
handlers are mouseMoveEvent and
mouseReleaseEvent.
Example cont.
void QSlider::mousePressEvent(...) {
emit valueChanged( newValue);
}

Slot is implemented QLCDNumber widget:
void QLCDNumber::display(int num) {
value = num;
}

Signal/Slot connection has been defined in the
following way:
connect( slider, SIGNAL( valueChanged(int) ), lcd,
SLOT( display(int) ) );
moc for Qt's C++ extensions
●

The meta-object compiler system in Qt:
1.The QObject class acts as a base class.
2.The Q_OBJECT, Q_PROPERTY etc. macros
inside the class declaration is used to enable
meta-object features (properties, signals,
slots...)
3.The Meta-Object Compiler (moc) supplies
each QObject subclass with the necessary
code to implement meta-object features.

✗

✗

The moc tool reads a C++ header file. If it finds one or more
class declarations that contain the Q_OBJECT macro, it
produces a C++ source file containing the meta-object code for
those classes.
Q_OBJECT macro
class Counter : public Qobject
{
Q_OBJECT
public:
counter() { value = 0; }
int value() const { return value; }

public slots:
void setValue(int value);

signals:
void valueChanged(int newValue);

private:
int value;
};
Qt's Meta Object Compiler
●

Moc provides the flexibility of Java's runtime
environments for C++.
–

maintains C++'s unique performance and
scalability advantages.

–

generates additional C++ code from the
header file which can then be compiled by any
C++ compiler

–

If you use qmake to create your makefiles,
build rules will be included that call the moc
when required.
How's code generation works?
I. moc reads C++ source files.
II.If class declaration contain the Q_OBJECT
macro, it produces another C++ source file
which contains the meta object code for those
class.
III.C++ source files must be linked with the
implementation of the class
IV.moc is normally automatically called during
building the program and programmer don't
have to do anything special to use moc.
uic (User Interface Compiler)
●

●

●

uic takes a user interface description in XML
format (.ui file) and then it can create compiled
C++ class
Qt's designer and Qt Creator uses this tool
when creating UI's
Also if you use qmake as a build tool, uic will be
invoked automatically for header files (.ui files).
–

Forms in .ui (XML) file format are compiled
during build process into C++ header files by
UIC compiler.

–

If the form is mycomponent.ui then UIC
generates ui_mycomponent.h. x
Qt Creator as a UI tool
Qt Events
●

●

In Qt, events are objects, derived from the
abstract QEvent class, that represent things
that have happened either within an application
or as a result of outside activity that the
application needs to know about. Events can be
received and handled by any instance of a
QObject subclass, but they are especially
relevant to widgets.
http://qt-project.org/doc/qt-5.1/qtcore/eventsandfilters.html
Qt Event types
●

●

Most events types have special classes,
notably QResizeEvent, QPaintEvent,
QMouseEvent, QKeyEvent, and QCloseEvent.
Each class subclasses QEvent and adds
event-specific functions. For example,
QResizeEvent adds size() and oldSize() to
enable widgets to discover how their
dimensions have been changed.
Qt Event
●

QMouseEvent class contains parameters that
describe a mouse event (like x,y position or
keyboard modifiers or )

void MyCheckBox::mousePressEvent(QMouseEvent *event)
{
    if (event­>button() == Qt::LeftButton) {
        // handle left mouse button here
    } else {
        // pass on other buttons to base class
        QCheckBox::mousePressEvent(event);
    }
}
Event handlers
void QWidget::mousePressEvent(QMouseEvent * event) 
[virtual protected]
–

This event handler, for event event, can be
reimplemented in a subclass to receive
mouse press events for the widget.

void QWidget::mouseReleaseEvent(QMouseEvent * event) 
[virtual protected]
–

●

This event handler can be reimplemented in
a subclass to receive mouse release events

Valid event types in Qt 5:
http://qt-project.org/doc/qt-5.1/qtcore/qevent.html#Type-enum
The model/view architecture
●

●

●

The model communicates with a
source of data, providing an
interface for the other
components in the architecture.
The view obtains model indexes
from the model, which are
references to data items
a delegate renders the items of
data.
–

When an item is edited, the
delegate communicates with
the model directly using
model indexes.
MVC architecture support
MVC implementation in Qt 4: The
model/view architecture
– easy to distinguish UI
elements from the data
– requires underlaying a data
model
● The data is fed back to the model
from the UI component
●
Qt Model's Views
●

Possible Views are:
–

QListView displays a list of items,

–

QTableView displays data from a model in a table,

–

QTreeView shows model items of data in a
hierarchical list.

–

Each of these classes is based on the
QAbstractItemView abstract base class
Item Views classes
●

Item view classes are similar than item view
classes provided by previous versions of Qt.
–

●

These are suitable for situations, where we
need to use only relatively few UI items.

Qt's convenience item view classes includes:
–
–

QTableWidget,

–
●

QListWidget,
QTreeWidget

These classes stores their data in "items"
–

QTableWidget contains QTableWidgetItems
etc.
QTableView
●

●

Qt's views (like QTableView, ) is used with a
data model, which can be a custom model or
one of Qt's predefined models.
If using table view model can be inherited from
QAbstractTableModel.
–

When subclassing QAbstractTableModel, you
must implement rowCount(), columnCount(),
and data().

–

Default implementations of the index() and
parent() functions are provided by
QAbstractTableModel.
Model classes
●

●

QAbstractItemModel is interface to data and
can handle views that represent data in the
form of tables, lists, and trees.
models for list and table-like data structures,
the QAbstractListModel and
QAbstractTableModel provides default
implementations of common functions
File/Database models
●

QStringListModel,

●

QStandardItemModel,

●

QFileSystemModel,
–

QFileSystemModel class provides functions for
renaming and removing files/ directories, and for
creating new directories in the local filesystem

●

QSqlQueryModel,

●

QSqlTableModel or QSqlRelationalTableModel
–

if the data is in a relational database, we can
combine a QTableView with a QSqlTableModel
GraphicsView
●

Graphics View Framework was developed for
Qt 4.2 and it's efficient for managing and
interacting 2D graphical object in the graphical
surface.
–

Has surface for managing and interacting with
a large number of 2D graphical items
efficiently

–

Provides a view widget for visualizing the
items, with support for zooming and rotation.

–

Graphics View provides an item-based
approach to graphical programming, much like
M/V classes QTableView, QTreeView and
Graphics View
●

QGraphicsView
–

The base class for Graphics View framework

–

most applications are built around a twodimensional canvas

–

a feeling of a custom widget without actually
creating a custom widget.
Graphics View basics
●

Three basic components: view, scene,item

●

These components are
–

QGraphicsView, shows the contents of a
scene

–

QGraphicsScene
●

–

manages collection of widgets, the propagation
of events and item's state like selection or
focus.

Each graphical item has subclass of
QGraphicsItem (single item/group of items)
QGraphicsItem
●

QGraphicsItem supports the following
features:
–

Basic Mouse events, and mouse hover and
wheel events.

–

Key events

–

Drag and drop

–

Grouping (QGraphicsItemGroup) of
graphical items

–

Transformations like transform, rotating,
scaling

–

Collision detection
Collision detection
–

QGraphicsItem supports also collision
detection
●

●

–

QGraphicsItem's collision detection uses
boundingRect() method
●

–

Detection collision is one of the base demand in
games
QGraphicsItem supports collision detection
through the shape() function, and collidesWith

It defines the outer bounds of the item as a
rectangle

The more fine grained collision algorithm is
based on calling shape which returns an
accurate outline of the item's shape
Collision intersection
●
●

You can specify how items and shapes collide
bool QGraphicsItem::collidesWithItem ( const
QGraphicsItem * other, Qt::ItemSelectionMode
mode = Qt::IntersectsItemShape)
–

Qt::ContainsItemShape

–

Qt::IntersectsItemShape (default mode)
●

other collides with this item if it either intersects,
contains, or is contained by this item's shape

–

Qt::ContainsItemBoundingRect

–

Qt::IntersectsItemBoundingRect
Localization in Qt
●
●

●

increasingly important in the global software market
In localization Qt programmers task is relatively
easy to do
In the source code put Qstring object into tr()
function
–

●

QLabel mystr(tr ("Hello World !"));

Function can be used even if it's not need to translate
right now
Translation in a program
// Setting Locales and translators for this applications
// Now use tr() function in every String
QString locale = QLocale::system().name();

QTranslator translator;
translator.load(QString("locales_") + locale);
// Testing with finish locale setting
// translator.load(QString("locales_fi"));
app.installTranslator(&translator);
tr() function and lupdate
●

QObject:: tr()
Returns the translation of the text or original
copy, if a translation does not exist
lupdate
–

●

The lupdate tool is used to synchronize source
code and translations.
lrelease
–

●

–

is used to create run-time translation files for use
by the released application.
TS files
●

TS files are XML files
–

You can edit these files by hand or using Qt
Linquist tool

<TS version="2.0" language="fi_FI">
<context>
<name>QLabel</name>
<message>
<source>Hello Colourful QT!</source>
<translation type="unfinished">Moi Varikas
Qt</translation>
</message>
</context>
Qt Linquist
●

●

Can use Qt Linquist translation program can be
used for editing translation files
QM files can be created as follows
lrelease is a command line tool that produces
QM files (binary format) out of TS files
– Qt Linquist programs (File / Release)
–
Qt Stylesheets
You can use CSS like language
● Basic process
– Create a stylesheet file (.qss
file)
● Should be in Qt resource file
also
– Insert stylesheet into the
application
●
Setting Stylesheet
Using Qt stylesheet in the code is
easy
● Use application wide settings if
possible because it's easier to modify
afterwards
●

QFile file(":/qstyle.qss");
if(file.open(QFile::ReadOnly) == true) {
// open file and set it to
// the style of the Qt application
QString styleSheet(file.readAll());
qss stylesheet language
●

Example of defining Qt stylesheet file in .qss
file:

QLabel {

font-weight: bold;

font-size: 15px;

border: 2px solid green;

border-radius: 4px;

QLabel:enabled { color: red }
QLabel:hover:enabled { color: black }
/* pseudo classes CSS like */

padding: 2px; }
Defining styles
●

●

●

You can reference component directly from
QSS using object's class#name like
(QDial#ageDial)
You can define stylesheet directly in source
code into component using method
QWidget::setStyleSheet()

button->setStyleSheet(

"QPushButton {color:white; background:rgb(255,255,0);
border-radius:10px; font:bold 16px;
font-family:"Arial";}”);
Dynamic effects with qss
●

:focus input focus

●

:hover mouse is moving over the component

●

:pressed clicked

●

:checked,:unchecked

●

●

:open, :close expanded or not :enabled
:disabled, :on, :off .
You can create realtime effects without
modified the Qt code
Qt 5 Resources
●

Qt 5 project: http://qt-project.org/

●

Tools: http://qt-project.org/downloads

●

Docs: http://qt-project.org/doc/

●

Qt Commercial: http://qt.digia.com/

●

●

●

KDE tutorial:
http://techbase.kde.org/Development/Tutorials/Us
Qt 5 features:
http://qt-project.org/wiki/Qt-5Features

Qt Location:
http://qt-project.org/wiki/Qt-5Features#90ef66eefd

More Related Content

What's hot

Introduction to Qt Creator
Introduction to Qt CreatorIntroduction to Qt Creator
Introduction to Qt CreatorQt
 
Qt Technical Presentation
Qt Technical PresentationQt Technical Presentation
Qt Technical PresentationDaniel Rocha
 
Qt Internationalization
Qt InternationalizationQt Internationalization
Qt InternationalizationICS
 
Best Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIBest Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIICS
 
In-Depth Model/View with QML
In-Depth Model/View with QMLIn-Depth Model/View with QML
In-Depth Model/View with QMLICS
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentICS
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3ICS
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickICS
 
Best Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IBest Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IICS
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? ICS
 
Meet Qt 6.0
Meet Qt 6.0 Meet Qt 6.0
Meet Qt 6.0 Qt
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptxGDSCVJTI
 
Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4ICS
 
Qt on Real Time Operating Systems
Qt on Real Time Operating SystemsQt on Real Time Operating Systems
Qt on Real Time Operating Systemsaccount inactive
 

What's hot (20)

Introduction to Qt
Introduction to QtIntroduction to Qt
Introduction to Qt
 
Introduction to Qt Creator
Introduction to Qt CreatorIntroduction to Qt Creator
Introduction to Qt Creator
 
Introduction to Qt programming
Introduction to Qt programmingIntroduction to Qt programming
Introduction to Qt programming
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 
Qt Technical Presentation
Qt Technical PresentationQt Technical Presentation
Qt Technical Presentation
 
Qt programming-using-cpp
Qt programming-using-cppQt programming-using-cpp
Qt programming-using-cpp
 
Qt Internationalization
Qt InternationalizationQt Internationalization
Qt Internationalization
 
Best Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIBest Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part II
 
In-Depth Model/View with QML
In-Depth Model/View with QMLIn-Depth Model/View with QML
In-Depth Model/View with QML
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3
 
Hello, QML
Hello, QMLHello, QML
Hello, QML
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt Quick
 
Best Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IBest Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part I
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
 
Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2
 
Meet Qt 6.0
Meet Qt 6.0 Meet Qt 6.0
Meet Qt 6.0
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptx
 
Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4
 
Qt on Real Time Operating Systems
Qt on Real Time Operating SystemsQt on Real Time Operating Systems
Qt on Real Time Operating Systems
 

Viewers also liked

Hybrid Apps with Qt
Hybrid Apps with QtHybrid Apps with Qt
Hybrid Apps with QtYnon Perek
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIICS
 
Introduction.to.design.patterns.in.cpp.with.qt.2nd.edition
Introduction.to.design.patterns.in.cpp.with.qt.2nd.editionIntroduction.to.design.patterns.in.cpp.with.qt.2nd.edition
Introduction.to.design.patterns.in.cpp.with.qt.2nd.editionValdomiro Morais
 
Airports can maximize capacity with minimal capital investment through effect...
Airports can maximize capacity with minimal capital investment through effect...Airports can maximize capacity with minimal capital investment through effect...
Airports can maximize capacity with minimal capital investment through effect...Ikusi Velatia
 
Qt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsQt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsJussi Pohjolainen
 
Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)vitalipe
 
Practical Model View Programming
Practical Model View ProgrammingPractical Model View Programming
Practical Model View ProgrammingMarius Bugge Monsen
 
Scripting Your Qt Application
Scripting Your Qt ApplicationScripting Your Qt Application
Scripting Your Qt Applicationaccount inactive
 
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개nemoux
 
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014Verold
 
qt-project.org and Qt 5
qt-project.org and Qt 5qt-project.org and Qt 5
qt-project.org and Qt 5thiagomacieira
 
Starting Development for Nokia N9
Starting Development for Nokia N9Starting Development for Nokia N9
Starting Development for Nokia N9tpyssysa
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design PatternsYnon Perek
 
Qt State Machine Framework
Qt State Machine FrameworkQt State Machine Framework
Qt State Machine Frameworkaccount inactive
 
Cutest technology of them all - Forum Nokia Qt Webinar December 2009
Cutest technology of them all - Forum Nokia Qt Webinar December 2009Cutest technology of them all - Forum Nokia Qt Webinar December 2009
Cutest technology of them all - Forum Nokia Qt Webinar December 2009Nokia
 
Introduction to WebGL and Three.js
Introduction to WebGL and Three.jsIntroduction to WebGL and Three.js
Introduction to WebGL and Three.jsJames Williams
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Andreas Jakl
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVICS
 
더 빠른 웹을 위해: HTTP/2
더 빠른 웹을 위해: HTTP/2더 빠른 웹을 위해: HTTP/2
더 빠른 웹을 위해: HTTP/2EungJun Yi
 

Viewers also liked (20)

Hybrid Apps with Qt
Hybrid Apps with QtHybrid Apps with Qt
Hybrid Apps with Qt
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
 
Introduction.to.design.patterns.in.cpp.with.qt.2nd.edition
Introduction.to.design.patterns.in.cpp.with.qt.2nd.editionIntroduction.to.design.patterns.in.cpp.with.qt.2nd.edition
Introduction.to.design.patterns.in.cpp.with.qt.2nd.edition
 
Airports can maximize capacity with minimal capital investment through effect...
Airports can maximize capacity with minimal capital investment through effect...Airports can maximize capacity with minimal capital investment through effect...
Airports can maximize capacity with minimal capital investment through effect...
 
Qt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsQt Memory Management & Signal and Slots
Qt Memory Management & Signal and Slots
 
Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)
 
Practical Model View Programming
Practical Model View ProgrammingPractical Model View Programming
Practical Model View Programming
 
Scripting Your Qt Application
Scripting Your Qt ApplicationScripting Your Qt Application
Scripting Your Qt Application
 
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
 
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
 
qt-project.org and Qt 5
qt-project.org and Qt 5qt-project.org and Qt 5
qt-project.org and Qt 5
 
Starting Development for Nokia N9
Starting Development for Nokia N9Starting Development for Nokia N9
Starting Development for Nokia N9
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
 
Qt State Machine Framework
Qt State Machine FrameworkQt State Machine Framework
Qt State Machine Framework
 
Cutest technology of them all - Forum Nokia Qt Webinar December 2009
Cutest technology of them all - Forum Nokia Qt Webinar December 2009Cutest technology of them all - Forum Nokia Qt Webinar December 2009
Cutest technology of them all - Forum Nokia Qt Webinar December 2009
 
WebGL and three.js
WebGL and three.jsWebGL and three.js
WebGL and three.js
 
Introduction to WebGL and Three.js
Introduction to WebGL and Three.jsIntroduction to WebGL and Three.js
Introduction to WebGL and Three.js
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IV
 
더 빠른 웹을 위해: HTTP/2
더 빠른 웹을 위해: HTTP/2더 빠른 웹을 위해: HTTP/2
더 빠른 웹을 위해: HTTP/2
 

Similar to Qt 5 - C++ and Widgets

下午3 intel fenghaitao_mee_go api and application development
下午3 intel fenghaitao_mee_go api and application development下午3 intel fenghaitao_mee_go api and application development
下午3 intel fenghaitao_mee_go api and application developmentcsdnmobile
 
Qt for beginners part 4 doing more
Qt for beginners part 4   doing moreQt for beginners part 4   doing more
Qt for beginners part 4 doing moreICS
 
Qt for Python
Qt for PythonQt for Python
Qt for PythonICS
 
Qt S60 Technical Presentation Fn Stripped
Qt S60 Technical Presentation Fn StrippedQt S60 Technical Presentation Fn Stripped
Qt S60 Technical Presentation Fn StrippedNokia
 
Plasmaquick Workshop - FISL 13
Plasmaquick Workshop - FISL 13Plasmaquick Workshop - FISL 13
Plasmaquick Workshop - FISL 13Daker Fernandes
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Johan Thelin
 
Guided overview of software frameworks qt framework
Guided overview of software frameworks   qt frameworkGuided overview of software frameworks   qt framework
Guided overview of software frameworks qt frameworkBenjamin Cottrell
 
IBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt IntegrationIBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt Integrationgjuljo
 
Qt Automotive Suite - under the hood // Qt World Summit 2017
Qt Automotive Suite - under the hood // Qt World Summit 2017Qt Automotive Suite - under the hood // Qt World Summit 2017
Qt Automotive Suite - under the hood // Qt World Summit 2017Johan Thelin
 
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with XgxperfDeveloping and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with XgxperfPrabindh Sundareson
 
Software Development Best Practices: Separating UI from Business Logic
Software Development Best Practices: Separating UI from Business LogicSoftware Development Best Practices: Separating UI from Business Logic
Software Development Best Practices: Separating UI from Business LogicICS
 
So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?Janel Heilbrunn
 
So I downloaded Qt, Now What?
So I downloaded Qt, Now What?So I downloaded Qt, Now What?
So I downloaded Qt, Now What?ICS
 
Migrating from Photon to Qt
Migrating from Photon to QtMigrating from Photon to Qt
Migrating from Photon to QtICS
 
Migrating from Photon to Qt
Migrating from Photon to QtMigrating from Photon to Qt
Migrating from Photon to QtJanel Heilbrunn
 
PyQt Application Development On Maemo
PyQt Application Development On MaemoPyQt Application Development On Maemo
PyQt Application Development On Maemoachipa
 
Porting Qt to a new Smartphone for Fun and Fame
Porting Qt to a new Smartphone for Fun and FamePorting Qt to a new Smartphone for Fun and Fame
Porting Qt to a new Smartphone for Fun and FameJarosław Staniek
 

Similar to Qt 5 - C++ and Widgets (20)

下午3 intel fenghaitao_mee_go api and application development
下午3 intel fenghaitao_mee_go api and application development下午3 intel fenghaitao_mee_go api and application development
下午3 intel fenghaitao_mee_go api and application development
 
Qt for beginners part 4 doing more
Qt for beginners part 4   doing moreQt for beginners part 4   doing more
Qt for beginners part 4 doing more
 
Qt for Python
Qt for PythonQt for Python
Qt for Python
 
Qt S60 Technical Presentation Fn Stripped
Qt S60 Technical Presentation Fn StrippedQt S60 Technical Presentation Fn Stripped
Qt S60 Technical Presentation Fn Stripped
 
Plasmaquick Workshop - FISL 13
Plasmaquick Workshop - FISL 13Plasmaquick Workshop - FISL 13
Plasmaquick Workshop - FISL 13
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011
 
Qt for S60
Qt for S60Qt for S60
Qt for S60
 
Guided overview of software frameworks qt framework
Guided overview of software frameworks   qt frameworkGuided overview of software frameworks   qt framework
Guided overview of software frameworks qt framework
 
IBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt IntegrationIBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt Integration
 
Treinamento Qt básico - aula I
Treinamento Qt básico - aula ITreinamento Qt básico - aula I
Treinamento Qt básico - aula I
 
Qt Automotive Suite - under the hood // Qt World Summit 2017
Qt Automotive Suite - under the hood // Qt World Summit 2017Qt Automotive Suite - under the hood // Qt World Summit 2017
Qt Automotive Suite - under the hood // Qt World Summit 2017
 
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with XgxperfDeveloping and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
 
Software Development Best Practices: Separating UI from Business Logic
Software Development Best Practices: Separating UI from Business LogicSoftware Development Best Practices: Separating UI from Business Logic
Software Development Best Practices: Separating UI from Business Logic
 
So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?
 
So I downloaded Qt, Now What?
So I downloaded Qt, Now What?So I downloaded Qt, Now What?
So I downloaded Qt, Now What?
 
Migrating from Photon to Qt
Migrating from Photon to QtMigrating from Photon to Qt
Migrating from Photon to Qt
 
Migrating from Photon to Qt
Migrating from Photon to QtMigrating from Photon to Qt
Migrating from Photon to Qt
 
PyQt Application Development On Maemo
PyQt Application Development On MaemoPyQt Application Development On Maemo
PyQt Application Development On Maemo
 
Porting Qt to a new Smartphone for Fun and Fame
Porting Qt to a new Smartphone for Fun and FamePorting Qt to a new Smartphone for Fun and Fame
Porting Qt to a new Smartphone for Fun and Fame
 
Cross Platform Qt
Cross Platform QtCross Platform Qt
Cross Platform Qt
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Qt 5 - C++ and Widgets

  • 1. Qt5 Qt 5 project: http://qt-project.org/ Tools: http://qt-project.org/downloads Docs: http://qt-project.org/doc/ Qt Commercial: http://qt.digia.com/ Lectures by Juha Peltomäki
  • 2. 5 Framework ● Qt5 – Cross Platform Framework – Qt5: http://qt-project.org/doc/ – Old Qt4: http://doc.qt.nokia.com/
  • 3. A cross-platform application development framework ● ● ● ● Using Qt, you can write applications and user interfaces once, and deploy them across many OS. In June 2008 Nokia acquired Trolltech ASA to enable the acceleration of their cross-platform software strategy for mobile devices and desktop applications. In August 2012 Digia announced its plans to acquire the Qt technology and business from Nokia. December 19, 2012 — Digia has announced the launch of Qt 5. – ”Qt 5 delivers a step function increase in performance, functionality and ease of use and will be the platform on which full Android and iOS support will be delivered during the coming year."
  • 4. Qt5 overview ● ● cross-platform, graphical, application development toolkit run applications on Windows, Mac OS X, Linux, and different embedded/mobile OSs – ● embedded Linux like Android, iOS, Blackperry, also some RTOS LInux OS like QNX are supported licensed under a professional (commercial, closed source) and GPL/ LGPL (open source)
  • 5. Qt5 Tools ● Qt Creator as a main IDE tools – ● Qt Creator should be the first choice for Qt beginners who want to get up and running quickly with Qt framework Qt Creator includes – – Qt Linquist for localization – ● Qt Designer for easy UI designing and building qmake to build apps to different target platforms Qt5 development tools: – http://qt-project.org/doc/qt-5.1/qtdoc/topics-app-development.html
  • 6. Qt libraries ● GUI and Widget libraries ● Networking ● XML ● SQL ● Container classes ● Multi-threading ● Animation ● Scripting ● QtQuick / QML
  • 7. Qt Creator ● Qt Creator - Originally Published at Oct '08 – a lightweight IDE – supports developing for different platforms – open and easily extendable – Context-sensitive help – Creating, editing and navigating code – supports the GNU compiler (gcc) and debugger – supports qmake build system
  • 8. Qt Designer ● GUI tools for rapid software development ● Separate easily UI from model classes – Much easier than manual UI coding – UI saved in XML files – Support for signals and slots mechanism – Support QML
  • 9. Qt programming environment ● ● ● ● Originally C++ based Framework Qt5 Supports also QML with JavaScript with support to C++ "backend" components supports single-source cross-platform development on Windows, Mac and Linux desktop and different embedded and mobile platforms (Blackberry 10, Android etc.) KDE Desktop environment is based on Qt Framework
  • 10. Links for Learning Qt ● ● Book Online: ”The Art of Building Qt Applications”: http://pyqt-doc-cn.googlecode.com/files/The_Art_of If you want to program purely in Qt/C++ and design your interfaces in code without the aid of any design tools, take a look at the Qt Tutorials.
  • 11. Qt5 - Getting started ● You can select 2 different approach to develop your Qt5 applications ● These are ● Qt5 Widgets – C++ based, traditional way ● ● ● QML, declarative UI language with JavaScript support http://qt-project.org/doc/qt-5.1/qtdoc/gettingstarted.html
  • 12. Qt Widgets ● The Qt Widgets Module provides a set of UI elements to create classic desktop-style user interfaces ● – http://qt-project.org/doc/qt-5.1/qtwidgets/qtwidgets-index.html QWidget class provides the basic capability to render to the screen, and to handle user input events.
  • 13. Qt Quick (QML) ● QtQuick and QML (Declarative UI language) – QtDeclarative creates a JavaScript runtime that QML runs with a Qt/C++ application ● ● ● can call C++ from QML and visa versa QML is easy enough for designers also, so UI can be prototyped very quickly with QML You can separate backend code from UI code easily so it enforces to use Model/View architecture in your application
  • 14. Qt Core Some Qt Core Source material: ● ● ● ● ● ● Classes: http://qt-project.org/doc/qt-5.1/qtdoc/qtmodules.html Qt Core: http://qt-project.org/doc/qt-5.1/qtcore/qtcore-index.html Object model: http://qt-project.org/doc/qt-5.1/qtcore/object.html Object trees: http://qt-project.org/doc/qt-5.1/qtcore/objecttrees.html MOC: http://qt-project.org/doc/qt-5.1/qtcore/metaobjects.html
  • 15. QtCore library Basic data types are supported ● ● ● ● ● Qt supports C++ basic types and basic classes Qt's own class types are used (QString, QVector etc.) in most cases basic data collection structures (vector, list, maps) are defined by Qt Even the basic data types are predefined by Qt Well-defined parent, child relationship between components
  • 16. Qt is dynamic ● Standard C++ has efficient run-time support but very static model ● Qt's Object model adds more dynamic model for creating GUI and possible to add dynamic properties using moc compiler
  • 17. Qt's Object model ● ● ● ● flexibility of Qt is basicly implemented in the Qt's Object Model. Qt features are implemented based on QObject using standard C++. Qt has it's own Meta-Object Compiler (moc). C++/GUI programming needs more flexibility and Qt provides it.
  • 18. Qt's features ● ● hierarchical object trees that organize object ownership in a natural way efficient object communication (signals and slots) ● dynamic properties of Object ● powerful events and event filters
  • 19. Qt's features ● guarded pointer (QPointer) is automatically set to 0 when the referenced object is destroyed ● ● ● normal C++ pointers become "dangling pointers" in such cases dynamic cast (qobject_cast) that works across library boundaries with every class inherit from QObject interval driven timers that make it possible to elegantly integrate many tasks in an eventdriven GUI
  • 20. QObject – the base class of Qt's Object hierarchy ● Has Unique name (QObject::objectName()) ● has a location in an object hierarchy ● ● can be connected to any other Qt Objects to emit/receive signals new dynamic properties can be added to it at runtime – Note! QObject and all subclasses of QObject have their copy constructor and assignment operator disabled.
  • 21. Qt data types ● ● QtGlobal header file declares several type definitions that guarantee a specified bit-size on all platforms supported by Qt for various basic types, for example qint8 which is a signed char guaranteed to be 8-bit on all platforms supported by Qt. Source: http://qt-project.org/doc/qt-5.1/qtcore/qtglobal.html
  • 22. QtCore Module ● ● ● The QtCore module contains core functionality to create business logic Some of most important and useful classes are listed below: QtCore classes ● ● ● QMetaObject - Contains meta-information about Qt objects QObject - The base class of all Qt objects QVariant - Acts like a union for the most common Qt data types
  • 23. QtCore Module continues ● QCoreApplication - Event loop for console Qt applications. For UI applications see QApplication class from QtGui module – ● ● Event loop is started with QCoreApplication::exec and uses exit() to exit from the main event loop. QEvent - is The base class of all event classes. Event objects contain event parameters QMetaObject class contains meta-information ● Also there is QtConcurrent namespace high-level APIs that make it possible to write multi-threaded programs more easily.
  • 24. QtCore - container classes ● ● ● ● ● QHash - Template class that provides a hash-tablebased dictionary QLinkedList lists Template class that provides linked QList - Template class that provides lists QMap - Template class that provides a skip-listbased dictionary QMultiHash - Convenience QHash subclass that provides multi-valued hashes
  • 25. QtCore container classes ● ● ● ● ● QMultiMap - Convenience QMap subclass that provides multi-valued maps QSet - Template class that provides a hash-tablebased set QStack - Template class that provides a stack QVector - Template class that provides a dynamic array QVectorIterator - Java-style const iterator for QVector and QStack
  • 26. QtCore char/string classes ● ● ● ● ● ● QString - Unicode character string (stores a string of 16-bit QChars) QStringList - List of Unicode strings QByteArray – store raw bytes or traditional 8-bits strings (const char *) QChar - 16-bit Unicode character QLatin1String - wrapper for Latin-1/ASCII encoded 8-bit string (see QString::toLocal8Bit ()) QRegExp - regular expression support for QStrings
  • 27. QtCore - multithread classes ● QRunnable - base class for all runnable objects ● QThread is for Platform-independent threads ● QThreadPool manages a collection of Qthreads ● Note! QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded programs without using low-level threading (introduced in Qt 4.4.)
  • 28. QtCore utility classes ● QDate - Date functions ● QDateTime - ● QTime - Clock time functions ● QTimer - Repetitive and single-shot timers ● Date and time functions QPoint - Defines a point in the plane using integer precision
  • 29. QtCore model classes ● ● ● QAbstractItemModel The abstract interface for item model classes QAbstractListModel Abstract model that can be subclassed to create one-dimensional list models QAbstractTableModelAbstract model that can be subclassed to create table models
  • 30. Qt Core file/XML classes ● ● ● QtextStream - Convenient interface for reading and writing text QDir - Access to directory structures and their contents QFile - Interface for reading from and writing to files ● QXmlStreamReader - Fast XML streaming API ● QXmlStreamWriter - streaming writer for XML
  • 31. JSON ● Starting from Qt 5.0 the Qt Core provides a set of classes to enable parsing and generating JSON documents.
  • 32. Qt GUI and Widgets ● Qt tutorial: – – ● ● http://qt-project.org/doc/qtcreator-2.8/creator-tutorials.html http://qt-project.org/doc/qt-5.1/qtdoc/topics-ui.html Qt UI Qt GUI – ● Qt Widgets – ● http://qt-project.org/doc/qt-5.1/qtwidgets/qtwidgets-index.html Qt Graphics – ● http://qt-project.org/doc/qt-5.1/qtgui/qtgui-index.html http://qt-project.org/doc/qt-5.1/qtdoc/topics-graphic
  • 33. QApplication and Event loop ● ● QApplication class manages the GUI application's control flow. It's has no graphical presentation but it's used in programs which has an graphical user interface. QApplication manages application's control flow and main setting:
  • 34. QApplication ● ● ● handles the application's initialization and finalization contains the main event loop where all events from the event sources are processed Setting includes mouse's wheel or double click settings and font setting and setting UI's look&feel style
  • 35. QApplication ● ● ● provides session management. handles most system-wide and application-wide settings (like application font or style) For any Qt GUI application there is always one QApplication object. – If you don't have GUI then use QCoreApplication instead
  • 36. QtWidgets ● The QtWidgets module extends QtCore with GUI functionality – ● The core class in QtWidgets module is The QWidget class which is the base class of all UI objects (like QMainWindow or QDialog). Note! When you use Qt Creator or Qt designer to create your UI you save it to XML format – Forms in .ui (XML) file format are compiled during build process into C++ header files by UIC compiler. – If the form is mycomponent.ui then UIC generates ui_mycomponent.h.
  • 37. Qt GUI before Qt 5 ● ● Prior to Qt 5.0, the Qt GUI module was the monolithic container for all things relating to graphical user interfaces in Qt, and included the Qt widget set, the item views, the graphics view framework and also printing. Starting Qt 5, these classes have been moved to the Qt Widgets module. Printing has been moved to the Qt Print Support module. Please note that these modules can be excluded from a Qt installation. http://qt-project.org/doc/qt-5.1/qtgui/qtgui-index.html
  • 38. Qt GUI in Qt 5 ● ● ● QWidget and all derived classes are a core part of Qt 5 on the Desktop. In Qt 5 you can still continue writing apps in exactly the same way as you have been doing with Qt 4.x. Qt5 is mainly source compatibility with Qt 4.x
  • 40. Layout ● ● If some graphical Qt widget should be displayed it need some form of layout to put into the form. All Qt's layouts are derived from the base class, QLayout. – Layouts are geometry managers that fit into the composition hierarchy of a graphical interface.
  • 41. Qt Layouts ● There are specific layout classes in Qt: – QHBoxLayout, QVBoxLayout – lines up widgets horizontally or vertically – QGridLayout – lays out widgets in grid – QStackedLayout - a stack of widgets
  • 43. QMainWindow ● ● When you want to create a bigger application, which handles many kind of input data and has lot of operation you should use main window to create your application. In the most Qt applications has a single QMainWindow. ● ● It can include many UI components (Qt widgets). It is the parent of all other widgets that are in the main window.
  • 44. QMainWindow ● It has some common features to all kind of desktop applications: ● ● Menu bar ● Status bar ● Toolbars ● ● A central widget Dock regions It's common practice to derive QMainWindow class to create own main window class.
  • 45. Qt widgets ● All Qt's widgets are derived from QWidget base class. – QWidget is a base class for all widgets in Qt – creating a new widget you have to subclass the QWidget class. – it has a visual representation on the screen – It is a reusable building block for creating UI – You can form any kind of widget, but also have to implements many methods – internal states, all repainting and size hinting are managed by own widget class
  • 46. More of QWidget ● ● ● It's a QObject, and thus can have parents, signals, slots, and managed children is a QPaintDevice, the base class of all widgets that can be draw on the screen can handle – signals responsing – event send by other widgets, – mouse, keyboard, other pointer devices – processes etc.
  • 48. QWidget methods ● Some of most important methods of QWidget in example: ● basic things: constructor, sizeHint etc. ● Painting: The paintEvent ● ● Mouse interaction: mousePressEvent, mouseMoveEvent, mouseReleaseEvent. Timing: The QTimer object is connected to the timeout slot
  • 49. Classes used in UI ● These classes doesn't have graphical presentation but these are commonly used with Qt widgets ● Qt Data types: QPoint and QSize . ● Controller classes: QApplication and QAction. ● Layouts: QHBoxLayout, QVBoxLayout, QGridLayout, etc.
  • 50. Non-visual classes ● Models: The QAbstractItemModel and its derived classes QAbstractListModel and QAbstractTableModel are part of Qt's Model/View framework, ● ● These models used as base classes for classes that represent data for a corresponding UI components like QListView, QtreeView, or QtableView. Database models: These are used with QTableView for using databases: QSqlTableModel and QSqlRelationalModel.
  • 51. Qt widgets categories ● ● ● Button widgets (etc.QPushButton, QRadioButton) Input widgets (etc.QLineEdit, QTextEdit, QDateEdit, QSlider ) Display widgets (QLabel, QProgressBar, QPixmap etc).
  • 52. Qt Widgets categories II ● ● ● Container widgets (QMainWindow, QFrame, QToolBar, QTabWidget ec.) Dialog widgets (QFileDialog, QInputDialog, QErrorMessage etc.) View widget (QListView, QTreeView, QTableView etc.)
  • 53. GUI classes I ● ● ● ● QAbstractItemModel model classes - abstract interface for item QAbstractItemView - basic functionality for item view classes QAbstractListModel - Abstract model that can be subclassed to create one-dimensional list models QAbstractTableModel -Abstract model that can be subclassed to create table models
  • 54. GUI classes II ● ● ● ● QAction - Abstract user interface action that can be inserted into widgets QActionEvent - Event that is generated when a QAction is added, removed, or changed QApplication - Manages the GUI application's control flow (event loop) and main settings QBoxLayout - Lines up child widgets horizontally or vertically ● QCheckBox - Checkbox ● QComboBox - Combined button and popup list
  • 55. Qt GUI classes III ● QCoreApplication applications - Event loop for console Qt ● QDial - Rounded range control ● QDialog - The base class of dialog windows ● QEvent - The base class of all event classes. ● ● ● objects contain event parameters QFileDialog - Dialog that allow users to select files/dirs QFormLayout - Manages forms of input widgets and their associated labels
  • 56. Qt GUI classes IV ● QGridLayout - Lays out widgets in a grid ● QHBoxLayout - Lines up widgets horizontally ● ● ● ● QImage - Hardware-independent image representation QInputDialog - Simple input dialog QInputEvent - The base class for events that describe user input QIntValidator - Validator for integer within a specified range
  • 57. Qt Gui classes V ● ● QKeyEvent - Describes a key event QLCDNumber - Displays a number with LCD-look digits ● QLabel - Text or image display ● QLayout - The base class of geometry managers ● QListView - List view onto a model ● QListWidget - Item-based list widget ● QMatrix - 2D transformations of a coordinate system
  • 58. Qt GUI classes VI ● QMenu ● QMenuBar - ● QMenuItem - an menu item ● QMessageBox - Simple Modal dialog ● QMouseEvent - ● - Menu widget for use in menus menu bar parameters describe a mouse event QPaintDevice - The base class of objects that can be painted
  • 59. Qt GUI classes VII ● ● ● QPaintEvent - Contains event parameters for paint events QPainter - Performs low-level painting on widgets and other paint devices QPicture - Paint device that records and replays QPainter commands ● QPixmap - Off-screen image representation ● QPushButton - Command button ● QRadioButton - Radio button with a text label
  • 60. Qt GUI classes VIII ● QScrollArea - Scrolling view onto another widget ● QSpinBox ● ● ● ● - Spin box widget QSplashScreen - Splash screen that can be shown during application startup QSplitter - Implements a splitter widget QStyle - Abstract base class that encapsulates the look and feel of a GUI QStyleFactory - Creates QStyle objects
  • 61. Qt GUI classes IX ● ● ● ● ● ● QTabBar - Tab bar, e.g. for use in tabbed dialogs QTableView- Default model/view implementation of a table view QTableWidget - Item-based table view with a default model QTextBrowser - Rich text browser QTextDocument - Holds formatted text that can be viewed and edited using a QTextEdit QTextEdit -Widget that is used to edit/display text
  • 62. Qt GUI classes X ● QToolBar - Movable panel that contains a set of controls ● QToolTip - balloon help ● QTranslator - Internationalization support ● ● ● QTreeView - Default model/view implementation of a tree view QTreeWidget - Tree view that uses a predefined tree model QVBoxLayout - Lines up widgets vertically
  • 63. Qt GUI programming features ● Signals and slots ● Moc ● Uic ● Qt Events
  • 64. GUI programming with Qt ● ● Qt's GUI library is very professional level framework This historically the most important reason why Qt has been so successful C++ framework for creating application. – KDE desktop environment has used Qt since 1996 ● http://www.kde.org/announcements/announcement.p
  • 65. Signals and slots ● In GUI programming, we want objects of any kind to be able to communicate with one another. – if a user clicks a Close button, we probably want the window's close() function to be called.
  • 66. Signals and Slots ● In Qt, we have an alternative to the callback technique: signals and slots. – It is slightly different way of thinking GUI events and event handling – C++ Macros and a preprocessor makes it feel as if the signal-slot syntax was part of standard C++ – All classes that inherit from QOobject or it's subclasses can contain signals and slots.
  • 67. Emitting signals ● Signals are emitted when QObject's state is changing – – ● doesn't need to care if there is any Object to handle signals object is like a reusable software component. A signal is emitted when a particular event occurs. – It's possible also to subclass widget and add our own signals to them.
  • 68. Slot ● A slot is a function that is called in response to a particular signal. – Qt's widgets have many pre-defined slots, but it is also possible to subclass widgets and add your own slots. ● Also QML supports signal-slot mechanism
  • 69. Q_OBJECT macro ● All classes that contain signals or slots must mention Q_OBJECT macro at the top of their declaration. – must also derive (directly or indirectly) from QObject
  • 70. QObject::connect ● connect function is a static function of QObject. – It creates connection between two QObject. bool QObject::connect ( const QObject * sender, const char * signal, const QObject * receiver, const char * method, Qt::ConnectionType type = Qt::AutoConnection ) QObject::connect(scrollBar, SIGNAL(valueChanged(int)), label, ● A signal-slot connection is removed when either of the objects involved are destroyed. – ● SLOT(setNum(int))); It's possible to disconnect connection with disconnect() method New signal/slot syntax in Qt5: http://qt-project.org/wiki/New_Signal_Slot_Syntax
  • 71. Example of signals and slot ● In the next example are used signals and slots mechanism to connect the QSlider's valueChanged() signal to the QLCDNumber's display() slot. – Signal is emitted in event handler method ● MousePressEvent can receive mouse press events for the widget. Other mouse event handlers are mouseMoveEvent and mouseReleaseEvent.
  • 72. Example cont. void QSlider::mousePressEvent(...) { emit valueChanged( newValue); } Slot is implemented QLCDNumber widget: void QLCDNumber::display(int num) { value = num; } Signal/Slot connection has been defined in the following way: connect( slider, SIGNAL( valueChanged(int) ), lcd, SLOT( display(int) ) );
  • 73. moc for Qt's C++ extensions ● The meta-object compiler system in Qt: 1.The QObject class acts as a base class. 2.The Q_OBJECT, Q_PROPERTY etc. macros inside the class declaration is used to enable meta-object features (properties, signals, slots...) 3.The Meta-Object Compiler (moc) supplies each QObject subclass with the necessary code to implement meta-object features. ✗ ✗ The moc tool reads a C++ header file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces a C++ source file containing the meta-object code for those classes.
  • 74. Q_OBJECT macro class Counter : public Qobject { Q_OBJECT public: counter() { value = 0; } int value() const { return value; } public slots: void setValue(int value); signals: void valueChanged(int newValue); private: int value; };
  • 75. Qt's Meta Object Compiler ● Moc provides the flexibility of Java's runtime environments for C++. – maintains C++'s unique performance and scalability advantages. – generates additional C++ code from the header file which can then be compiled by any C++ compiler – If you use qmake to create your makefiles, build rules will be included that call the moc when required.
  • 76. How's code generation works? I. moc reads C++ source files. II.If class declaration contain the Q_OBJECT macro, it produces another C++ source file which contains the meta object code for those class. III.C++ source files must be linked with the implementation of the class IV.moc is normally automatically called during building the program and programmer don't have to do anything special to use moc.
  • 77. uic (User Interface Compiler) ● ● ● uic takes a user interface description in XML format (.ui file) and then it can create compiled C++ class Qt's designer and Qt Creator uses this tool when creating UI's Also if you use qmake as a build tool, uic will be invoked automatically for header files (.ui files). – Forms in .ui (XML) file format are compiled during build process into C++ header files by UIC compiler. – If the form is mycomponent.ui then UIC generates ui_mycomponent.h. x
  • 78. Qt Creator as a UI tool
  • 79. Qt Events ● ● In Qt, events are objects, derived from the abstract QEvent class, that represent things that have happened either within an application or as a result of outside activity that the application needs to know about. Events can be received and handled by any instance of a QObject subclass, but they are especially relevant to widgets. http://qt-project.org/doc/qt-5.1/qtcore/eventsandfilters.html
  • 80. Qt Event types ● ● Most events types have special classes, notably QResizeEvent, QPaintEvent, QMouseEvent, QKeyEvent, and QCloseEvent. Each class subclasses QEvent and adds event-specific functions. For example, QResizeEvent adds size() and oldSize() to enable widgets to discover how their dimensions have been changed.
  • 81. Qt Event ● QMouseEvent class contains parameters that describe a mouse event (like x,y position or keyboard modifiers or ) void MyCheckBox::mousePressEvent(QMouseEvent *event) {     if (event­>button() == Qt::LeftButton) {         // handle left mouse button here     } else {         // pass on other buttons to base class         QCheckBox::mousePressEvent(event);     } }
  • 82. Event handlers void QWidget::mousePressEvent(QMouseEvent * event)  [virtual protected] – This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget. void QWidget::mouseReleaseEvent(QMouseEvent * event)  [virtual protected] – ● This event handler can be reimplemented in a subclass to receive mouse release events Valid event types in Qt 5: http://qt-project.org/doc/qt-5.1/qtcore/qevent.html#Type-enum
  • 83. The model/view architecture ● ● ● The model communicates with a source of data, providing an interface for the other components in the architecture. The view obtains model indexes from the model, which are references to data items a delegate renders the items of data. – When an item is edited, the delegate communicates with the model directly using model indexes.
  • 84. MVC architecture support MVC implementation in Qt 4: The model/view architecture – easy to distinguish UI elements from the data – requires underlaying a data model ● The data is fed back to the model from the UI component ●
  • 85. Qt Model's Views ● Possible Views are: – QListView displays a list of items, – QTableView displays data from a model in a table, – QTreeView shows model items of data in a hierarchical list. – Each of these classes is based on the QAbstractItemView abstract base class
  • 86. Item Views classes ● Item view classes are similar than item view classes provided by previous versions of Qt. – ● These are suitable for situations, where we need to use only relatively few UI items. Qt's convenience item view classes includes: – – QTableWidget, – ● QListWidget, QTreeWidget These classes stores their data in "items" – QTableWidget contains QTableWidgetItems etc.
  • 87. QTableView ● ● Qt's views (like QTableView, ) is used with a data model, which can be a custom model or one of Qt's predefined models. If using table view model can be inherited from QAbstractTableModel. – When subclassing QAbstractTableModel, you must implement rowCount(), columnCount(), and data(). – Default implementations of the index() and parent() functions are provided by QAbstractTableModel.
  • 88. Model classes ● ● QAbstractItemModel is interface to data and can handle views that represent data in the form of tables, lists, and trees. models for list and table-like data structures, the QAbstractListModel and QAbstractTableModel provides default implementations of common functions
  • 89. File/Database models ● QStringListModel, ● QStandardItemModel, ● QFileSystemModel, – QFileSystemModel class provides functions for renaming and removing files/ directories, and for creating new directories in the local filesystem ● QSqlQueryModel, ● QSqlTableModel or QSqlRelationalTableModel – if the data is in a relational database, we can combine a QTableView with a QSqlTableModel
  • 90. GraphicsView ● Graphics View Framework was developed for Qt 4.2 and it's efficient for managing and interacting 2D graphical object in the graphical surface. – Has surface for managing and interacting with a large number of 2D graphical items efficiently – Provides a view widget for visualizing the items, with support for zooming and rotation. – Graphics View provides an item-based approach to graphical programming, much like M/V classes QTableView, QTreeView and
  • 91. Graphics View ● QGraphicsView – The base class for Graphics View framework – most applications are built around a twodimensional canvas – a feeling of a custom widget without actually creating a custom widget.
  • 92. Graphics View basics ● Three basic components: view, scene,item ● These components are – QGraphicsView, shows the contents of a scene – QGraphicsScene ● – manages collection of widgets, the propagation of events and item's state like selection or focus. Each graphical item has subclass of QGraphicsItem (single item/group of items)
  • 93. QGraphicsItem ● QGraphicsItem supports the following features: – Basic Mouse events, and mouse hover and wheel events. – Key events – Drag and drop – Grouping (QGraphicsItemGroup) of graphical items – Transformations like transform, rotating, scaling – Collision detection
  • 94. Collision detection – QGraphicsItem supports also collision detection ● ● – QGraphicsItem's collision detection uses boundingRect() method ● – Detection collision is one of the base demand in games QGraphicsItem supports collision detection through the shape() function, and collidesWith It defines the outer bounds of the item as a rectangle The more fine grained collision algorithm is based on calling shape which returns an accurate outline of the item's shape
  • 95. Collision intersection ● ● You can specify how items and shapes collide bool QGraphicsItem::collidesWithItem ( const QGraphicsItem * other, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) – Qt::ContainsItemShape – Qt::IntersectsItemShape (default mode) ● other collides with this item if it either intersects, contains, or is contained by this item's shape – Qt::ContainsItemBoundingRect – Qt::IntersectsItemBoundingRect
  • 96. Localization in Qt ● ● ● increasingly important in the global software market In localization Qt programmers task is relatively easy to do In the source code put Qstring object into tr() function – ● QLabel mystr(tr ("Hello World !")); Function can be used even if it's not need to translate right now
  • 97. Translation in a program // Setting Locales and translators for this applications // Now use tr() function in every String QString locale = QLocale::system().name(); QTranslator translator; translator.load(QString("locales_") + locale); // Testing with finish locale setting // translator.load(QString("locales_fi")); app.installTranslator(&translator);
  • 98. tr() function and lupdate ● QObject:: tr() Returns the translation of the text or original copy, if a translation does not exist lupdate – ● The lupdate tool is used to synchronize source code and translations. lrelease – ● – is used to create run-time translation files for use by the released application.
  • 99. TS files ● TS files are XML files – You can edit these files by hand or using Qt Linquist tool <TS version="2.0" language="fi_FI"> <context> <name>QLabel</name> <message> <source>Hello Colourful QT!</source> <translation type="unfinished">Moi Varikas Qt</translation> </message> </context>
  • 100. Qt Linquist ● ● Can use Qt Linquist translation program can be used for editing translation files QM files can be created as follows lrelease is a command line tool that produces QM files (binary format) out of TS files – Qt Linquist programs (File / Release) –
  • 101. Qt Stylesheets You can use CSS like language ● Basic process – Create a stylesheet file (.qss file) ● Should be in Qt resource file also – Insert stylesheet into the application ●
  • 102. Setting Stylesheet Using Qt stylesheet in the code is easy ● Use application wide settings if possible because it's easier to modify afterwards ● QFile file(":/qstyle.qss"); if(file.open(QFile::ReadOnly) == true) { // open file and set it to // the style of the Qt application QString styleSheet(file.readAll());
  • 103. qss stylesheet language ● Example of defining Qt stylesheet file in .qss file: QLabel { font-weight: bold; font-size: 15px; border: 2px solid green; border-radius: 4px; QLabel:enabled { color: red } QLabel:hover:enabled { color: black } /* pseudo classes CSS like */ padding: 2px; }
  • 104. Defining styles ● ● ● You can reference component directly from QSS using object's class#name like (QDial#ageDial) You can define stylesheet directly in source code into component using method QWidget::setStyleSheet() button->setStyleSheet( "QPushButton {color:white; background:rgb(255,255,0); border-radius:10px; font:bold 16px; font-family:"Arial";}”);
  • 105. Dynamic effects with qss ● :focus input focus ● :hover mouse is moving over the component ● :pressed clicked ● :checked,:unchecked ● ● :open, :close expanded or not :enabled :disabled, :on, :off . You can create realtime effects without modified the Qt code
  • 106. Qt 5 Resources ● Qt 5 project: http://qt-project.org/ ● Tools: http://qt-project.org/downloads ● Docs: http://qt-project.org/doc/ ● Qt Commercial: http://qt.digia.com/ ● ● ● KDE tutorial: http://techbase.kde.org/Development/Tutorials/Us Qt 5 features: http://qt-project.org/wiki/Qt-5Features Qt Location: http://qt-project.org/wiki/Qt-5Features#90ef66eefd