/
Qt  Framework Qt  Framework

Qt Framework - PowerPoint Presentation

alida-meadow
alida-meadow . @alida-meadow
Follow
493 views
Uploaded On 2017-10-18

Qt Framework - PPT Presentation

Qt History Who uses Qt Benefits Tools and components SDK Core Internals Programming with Qt Programming with Qt Containers Tulips 2D3D graphics Widgets Graphics View ID: 597110

framework object event class object framework class event system model widgets graphics slots thread support core programming internals classes

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Qt Framework" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Qt Framework

Qt

History

Who uses

Qt

Benefits

Tools and components

SDK

Core Internals

Programming with

QtSlide2

Programming with

Qt

- Containers (Tulips) - 2D/3D graphics

- Widgets - Graphics View

- XML - Thread/IPC

- Interview (MVC) - Phonon

-

Webkit

- Multimedia

- Canvas - OpenGL

- Database

- QML and JavaScript

- Networking - Android and

iOSSlide3

Qt

Framework

Qt

History

Who uses

Qt

Benefits

Tools and components

SDK

Core Internals

Programming with

QtSlide4

Qt

History

Pronounce “Cute” or

Qt

Cross platform application development framework

User experience across hardware platforms

It goes beyond GUI (database access, xml parser, web, …)

It can bind to any language and can be written in

C++, python

, C#, Ruby, Ada, Pascal, PHP, Perl, and Java. Slide5

Qt

History

Qt

Was

initially developed by two

persons,

Haavard

Nord (CEO), and

Eirik

Chambe

(President) in early 90.

B

oth

graduated from

Norwegian Institute

of

Technology in Computer Science and formed

Throlltech

Inc. in 1995.

Qt

4 was published in Summer 2005 (major milestone)

In 2008 acquired by Nokia (Finnish company)

In 2012, acquired by

Digia

(Finnish company)

3 licenses (GPL/GNU GPL/Commercial)

The commercial you don’t have to share the code in open sourceSlide6

Qt

History

T

raditional C++, but later (4.7) with

Qt

Quick and QML with JavaScript where it is ideal for tablet/smartphone

Leverage with C++ , less learning curve

It is high quality, mature, free, excellent support for localization, support 32/64 bit computing

Presently

Qt

5.2 and

Qwt

6.1 (latest version)

Rich set of Widgets (1000+),

Qwt

(125

+) classes

Very Good Documentation, help, and examples

Qt

Project: http://

www.qt-project.org

Digia

Site: http://qt.digia.comSlide7

Qt

Framework

Qt

History

Who uses

Qt

Benefits

Tools and components

SDK

Core Internals

Programming with

QtSlide8

Who uses

Qt

European Space Agency

Google Earth

Skype

KDE (Operating System Dist. on Linux)

Adobe Photoshop Album (graphics)

Autodesk Maya (Animation)

VLC (Video)

Panasonic and Thales IFE (Airline)

Navico

(Navigation)

Eykona

(healing process monitor)

Barco (Medical Imaging)

Michelin, Intel, HP, Samsung, Blackberry, ABB, AMD, Epson, HONDA, Cannon, …Slide9

Qt

Framework

Qt

History

Who uses

Qt

Benefits

Tools and components

SDK

Core Internals

Programming with

QtSlide10

Benefit

Cross platform GUI framework

(develop on one machine and port it to any other machine)

Rich API class w/ C++ library

, along an

IDE

with different

tools

to support

Superior Graphics performance

with power of C++ and

Qt

Object Model

A

very powerful mechanism for seamless object communication called

signal sand slots

(callback system)

Query able and designable object properties

Contextual string translation for internationalization

Sophisticated interval driven timers

that make it possible to elegantly integrate many tasks to an event driven GUI

Hierarchical and query able object trees that organize object in a natural way

Guarded pointers (

QPointer

) that are automatically

set

to 0 when the referenced object get destroyed

A dynamic cast that works across library boundarySlide11

Qt

Framework

Qt

History

Who uses

Qt

Benefits

Tools and components

SDK

Core Internals

Programming with

QtSlide12

Tools

Qt

Creator : Cross platform IDE

Qt

Designer: GUI layout and forms builder

Qt

Linguest

: Internationalization toolset

Qt

Assist: Customizable documentation reader

Qt

Qmake

: Cross platform build tool

Plugin for other IDE: Integration with Visual Studio and Eclipse

Configure: Tool to configure

Qt

on any specific platform

Qt

SDK: Rich C++ librarySlide13

Qt

Modular Class LibrarySlide14

Building

Qt

Application (

Qmake

)

Qmake

: Creates

Qt

Project file (.pro) ,

c

an also be created manually.:

$

Qmake

project (generates “hello.pro”)

$

qmake

hello.pro(generates

Makefile

”)

$

make

(use

nmakeif

running on Windows)

Qmake

: Uses the .pro file as input produces platform specific

Makefiles

)

Generates make rules to invoke

moc

for project header files containing Q-Object

Make: Compiles the program for the current platform

Executes also

moc

,

uic

and

rccSlide15

Qt

Framework

Qt

History

Who uses

Qt

Benefits

Tools and components

SDK

Core Internals

Programming with

QtSlide16

Qt

ArchitectureSlide17

Qt

SDK

The

Qt

class library encompasses all the functions needed build robust, high end applications, and they can be

s

eparate into several modules:

Core Framework - OpenGL framework

GUI

Framework -2D with Painter framework

SQL Framework - Scene Graph framework

XML

Framework - SVG Framework

Networking Framework

OpenGL

Framework

Multimedia Framework

WebKit

Framework

Phonon

Framework Slide18

Qt

Class Library

QtCore

:

File

I/O

, event and object

handling, multi-threading and concurrency, plugins

, setting

management signals

and

slots

inter-object communications mechanism

QtGui

:

S

et

of customizable

widgets, 2D

graphics canvas and OpenGL®

integration, powerful

font and layout engine

s

tyle

engine and widget

style sheets, anti-aliasing

, vector deformation, and SVG

support, advanced

graphics effects

s

upport

for ARGB top-level widgetsSlide19

Qt

Framework

Qt

History

Who uses

Qt

Benefits

Tools and components

SDK

Core Internals

Programming with

QtSlide20

Core Internals

Object Model

Meta Object System

Property System

Signal and Slots

State Machine Framework

TimersSlide21

Core Internals

Object Model

Meta Object System

Property System

Signal and Slots

Event SystemSlide22

Object Model

Qt’s

Object Model (

QObject

)

GUI programming

is a domain that requires both runtime efficiency and a high level of flexibility.

Although C++ object model is efficient at runtime but its static nature is inefficient in graphical domain.

Qt

provides this, by combining the speed of C++ with the flexibility of the

Qt

Object Model.

Meta-Object system : Allows runtime introspection, manipulation and

invocation of properties and methods in the object. Slide23

Core Internals

Object Model

Meta Object System

Property System

Signal and Slots

Event SystemSlide24

Meta Object System

The

QMetaObject

class contains meta-information about

Qt

objects.

Classes must be predefined with

Qt

moc

Class declarations must include Q_OBJECT macro

 

Responsible

for the

signals/slots

inter-object communication mechanism, runtime type information, and the

Qt

property system

Qmake

takes care of this automaticallySlide25

Core Internals

Object Model

Meta Object System

Property System

Signal and Slots

State Machine Framework

TimersSlide26

Property Systems

P

rovides

a sophisticated property

system

Does not

rely on non-standard compiler features like __property or [property].

Works with

 

any

 standard C++ compiler on every platform

Qt

supports.

To declare a property,

use the

 

Q_PROPERTY

()

 macro in a class that inherits 

QObject

.

Q_PROPERTY(type name

READ

getFunction

[WRITE

setFunction

]

[RESET

resetFunction

]

[NOTIFY

notifySignal

]

[DESIGNABLE

bool

]

[SCRIPTABLE

bool

]

[STORED

bool

]

[USER

bool

]

[CONSTANT]

[FINAL])Slide27

Property Systems

K

eep

track of a priority

value.

priority

(name of property) and its type will be enumeration

type named 

Priority

class

MyClass

: public

QObject

{

Q_OBJECT

Q_PROPERTY(Priority

priority

READ,

priority WRITE,

setPriority

NOTIFY

priorityChanged

)

Q_ENUMS(Priority

) Slide28

Core Internals

Object Model

Meta Object System

Property System

Signal and Slots

Event SystemSlide29

Callbacks

Traditional callbacks (a pointer to a function)

Problems: not type safe: does the caller use the correct arguments?

Observer Pattern

Called when appropriate (event notification, …)

Many to many relationship

Loose coupling between signals and slots

Less generic: callback strongly coupled to processing function

Processing function must which callback to call.Slide30

Inter-Object Communication

The user clicks the OK button

-What happens?

How do we react to the button press?

Answer:

-Signals and slots

Type safe callbacks

Signals are emitted by objects

Slots are function that react to signals

Slots are regular method calls

Handled entirely by

Qt’s

meta object system Slide31

Signals and Slots

Signal and Slots run at the run time

Use the “

connect

” method to join signal and slots

connect(

slider,

SIGNAL

(

valueChanged

( double )

) ,

plot

,

SLOT(

setIntervalTime

(double

)));

Predefined signals and slots by classes

Otherwise you have to write it depends of what you need

In the header file:

Q_SIGNALS(signals):

Q_SLOTS(slots):

Parsed by

Qt’s

Meta Object Compiler (

moc

)

Same type, and number of parametersSlide32

Signals

A signal is a way to inform a possible observer something of interest has happened inside the observed class

A

PushButton

clicked (an

a

synchronous service) where the value of Slider is changing.

Signals are member functions that automatically implements in the meta-object

Only the function declaration is provided by the developer

Signal is sent, or emitted using the keyword emit ( i.e. Emit

someSignal

(“Hello”) )Slide33

Slots

Regular class member methods

Should be declared as void

Slots can return a value when called as a method

Return values are ignored when invoked from a signal

May include in access

specifier

(pubic, private, ..)

A slot is a function that is to be executed when a signal has been emitted: (i.e. when

QPushButton

is pressed, Close a

Qdialog

)Slide34

Core Internals

Object Model

Meta Object System

Property System

Signal and Slots

Event SystemSlide35

Event Systems

Events

are objects, derived from abstract

QEvent

class, usually receives from window system and dispatch it to widgets.

When

an event occurs,

Qt

Creates an event object (an instance of the

QEvent

),

and therefore delivers to an instance of

QObject

.

Based on the type of event delivered, response will be send if the event was accepted or ignored

Such as

QMouseEvent

 and 

QKeyEvent

, come from the window system; Slide36

How Events are

Delivered

When

an event occurs,

Qt

C

reates

an event object

(an

instance of the

QEvent

),

D

elivers

it to a particular instance of 

QObject

Based on the type of event delivered, response will be send if the event was accepted or ignored

Such as

QMouseEvent

 and 

QKeyEvent

, come from the window system; Slide37

How Events are

Delivered Slide38

Event

Types

Most events types have special classes, notably 

QResizeEvent

QPaintEvent

QMouseEvent

QKeyEvent

,

QCloseEvent

.

Each

class subclasses 

QEvent

 and adds event-specific

functions.

For example

QResizeEvent

 

adds

 

size

()Slide39

Hello WorldSlide40

Hello WorldSlide41

Concepts in

Qt

Widgets

Application

Main Window

Desktop Integration

Dialog Windows

Layout Management

Model/View ProgrammingSlide42

Application Main Window

C

lasses

for managing main windows and associated

UI components

:

QMainWindow

:

 is the central class around which applications can be

built on top level UI.

QDockWidget

:

 provides a widget that can be used to create detachable tool palettes or helper windows.

QToolBar

: provides

a generic toolbar widget that can hold a number of different action-related widgets, such as buttons, drop-down menus,

combo boxes

, and spin boxes. Slide43

Desktop Integration

These

classes enable developers to take advantage of native

services

while still using a cross-platform API

.

QDesktopServices

:

 provides an interface to services offered by the user's desktop

environment (such as

openUrl

()

 

function).

QSystemTrayIcon

:

docks or panels with 

system trays

 in which applications can install

icons,

to display status information, either by updating the icon itself or by showing information in "balloon messages

".

QDesktopWidget

: to

monitor the positions of widgets and notify applications about changes to the way the desktop is split over the available screens. This enables applications to implement policies for positioning new windows so that, for example, they do not distract a user who is working on a specific task.Slide44

Dialogs

ColorDialog

Dialog component for choosing a color.

FileDialog

Dialog component for choosing files from a local

file system

.

FontDialog

Dialog component for choosing a font.

MessageDialog

Dialog component for displaying popup messages.Slide45

Layout Classes

QHBoxLayout

:

Lines up widgets

horizontally.

QVBoxLayout

:

Lines

up widgets

vertically.

QGridLayout

:

Lays

out widgets in a

grid.

QStackedWidget

:

Stack

of widgets where only one widget is visible at a

time

QStackedLayout

:

Stack

of widgets where only one widget is visible at a

time

QFormLayout

:

Manages

forms of input widgets and their associated

labels

And many more …Slide46

Qt

Strings

Built-in Unicode support,

Useful methods (i.e. trimmed(), split())

Cheap copying (implicit sharing)

Believe it or not, they can actually contain embedded ‘\0’ characters …

Concatenation and formatting:

Qstring

first = Joe”;

Qstring

last = “Doe”;

Qstring

fullname

= first + “ “+ last;

Qstring

fullname2 =

Qstring

(“%1 %2).

arg

(first).

arg

(last));

Translation:

Qstring

translatedSend

=

tr

(“Send”);Slide47

Qt

Strings

Splitting/Joining on a delimiter character

QString

numbers = “1, 2,3,4,45,6,23”;

QStringList

nums

=

numbers.split

(‘,’);

int

sum=0;

f

oreach

(

Qstring

num

,

numberList

)

Sum +=

num.toInt

();

Removing leading or trailing whitespace:

QString

name = “ Joe Doe”;

QString

trimedName

=

name.trimmed

();Slide48

Model/View Programming (1)

Qt

uses

a model/view architecture to manage

the

relationship between data and the way it

is

presented to the user

.

MVC consists of 3

kinds of

objects, the “

Model

is

the application object, the

View

is its screen

presentation

, and the

Controller

defines the

way

the user interface reacts to user input.

You have data, and you put part of data into model, View renders and displays the data.Slide49

Model/View Programming (3)Slide50

Model/View Programming (2)

Add headers

Add in private sectionSlide51

Model/View Programming (4)Slide52

Qt

Tulips

Container objects STL-like collection classes

Sequential

(lists, vectors, queues, and stacks) and

Associative

(Sets, hashes, maps)

Use implicit sharing (i.e. copy on write) thread safe

Supports both STL and Java Style iterators

Wrapper STL like collection classes, lighter, safer than STL classes

Efficient use for objects referenced by value

Includes important algorithm (i.e. copy, sort, find, count, remove, fill, comparison,)Slide53

Qt

XML

Simple XML

streamreader

and writer

A well formed XML parser using SAX2 (Simple API for XML) interface, as well as DOM level 2 (Document Object Model)

XMLPattern

module

An implementation of the XQuery standard

Enable users to query XML files similar to SQL

Semantics for value assignment, filtering, and simple operations

Fully

controlable

out formatting

XSLT supportSlide54

Qt

Webkit

Based on the Open Source

Webkit

engine

Webkit

is basis for Apple's Safari

browser

, and numerous other

browsers (i.e. Safari, Chrome, and iPhone, http://webkit.org)

Apple originally based

Webkit

on

KHTML/KJS

from

KDE (done with QT)

QWebkit

is web rendering engine, JavaScript engine, and provides classes for integrating

Qt

and web content to create hybrid applications

Capabilities can do HTML4 and parts of HTML5 (2D canvas, Audio/Video playback, off-line apps, web workers, storage and SQL database)

In addition, CCS1 and CCS2 and part of CSS3 (Backgrounds and borders, fonts, 2D/3D transformations, transitions and animations)

It is done via “

QWebView

”, “

QWebPage

”, and “

QWebFrame

” classes

The DOM (Document Object Model) is accessible through the “

QWebElement

” class.Slide55

Qt

Phonon

Single easy to use API for playback

Provides possibility to play/synchronize multiple sound/video streams

Will use native back-end format support

DirectShow

GStreamer

QuickTime

MVF (Symbian)

Plan to add more video and other authoring support in futureSlide56

Qt

Canvas

Alternative to

QPainter

(but may still use

QPainter

).

QCanvas

 

where you

put graphical objects like polygons,

texts,

pixmaps

.

It also provides

additional items by

subclassing

 

QCanvasItem

 

or

one of its more specialized

subclasses.

Supports huge numbers of

figures

.

Supports

checking for overlap (collision) of

figures

.

Supports

checking for collision with a

QPoint

.

Optimized

to reduce

flicker

, even with lots of

figures.

QCanvasView

is used

to display

and

CanvasPolygonalItem

for manipulating objectsSlide57

Qt

OpenGL

QGLWidget

is the class supporting the OpenGL in

Qt

A widget for rendering OpenGL graphics.

More than 250 functions to produce 3D scene

You can run 2D as well as 3D, and it is cross platform

QGLWidget

provides functionality for displaying OpenGL graphics integrated into a

Qt

application

.

The

QGLWidget

creates a GL overlay context in addition to the normal context if overlays are supported by the underlying system

.

Improves drastically performance on threading with “buffer swapping”, “Texture uploading”, as well as “

QPainter

”Slide58

Qt

GraphicsView

Painting is primitive graphics (

QPainting

, i.e. Photoshop).

Problem: low level abstraction, and low reuse

Drawing is structured graphics, with high level of abstraction and high reuse (

QGraphicsView

). Illustrator is an example.

Q

is a structured graphics, Object Oriented, can do composition (like a house, square shape and we can make it rectangle, transform it, and …)and we can move them, transform them, stacked them , and … like KDE desktop it is done completely by

QGraphicsView

QGraphicsView

is based on Model/View architecture

It efficiently manage a large number of items, event propagation, resolution independent, and animation supportSlide59

Qt

Graphics

View

The Graphics View Frameworks is

a

scene

based

approach to

graphics

QGraphicsItem

,

QGraphicsScene

, and

QGraphicsView

You have more control over the widget shape and overlapping

This will support more items and much more flexible to move around

The

QGraphicsScene

class contains all

items

and acts as an interface between

the

view and the

items

It

is based on

BSP

(Binary Space Partitioning trees store

items

in a tree, depending on their

location

in

space) and

therefore extremely efficient in terms of performance.Slide60

Qt

Multimedia

Multimedia support in

Qt

is provided by the

Qt

Multimedia

module

Provides a

rich feature set that enables you to easily take advantage of a platforms multimedia

capabilities

and

H/W.

This ranges from the playback and recording of audio and video content to the use of available devices like cameras and radios

.

There are components for

Audio, Video, Camera

, as well as

Radio

Some of the features:

Access raw radio, play and record, compress, decode and access audio and video frames.Slide61

Qt

Networking

Classes for writing TCP/IP clients and servers

Provides

access

to

the web without any connections to a user

interface and handles requests/replies, cache

web

pages, keep

track of

cookies, use proxies, act

as a protocol

translator.

Browsing the web uses the

HTTP, TCP/IP, FTP, SMTP, POP and IMAP protocols.

Supports accessing TCP

and UDP directly at

socket level

2

TCP classes in

Qt

:

QTcp

(

Udp

)Socket and

QTcp

(

Udp

)Server.

The

QtWebKit

classes uses the “

QNetworkAccessManager

” to access the

net.Slide62

Qt

Networking

 

QNetworkAccessManager

 to handle network communication

.

TCP

(Transmission Control Protocol) is a low-level network protocol used by most Internet protocols, including HTTP and FTP, for data transfer. It is a reliable, stream-oriented, connection-oriented transport protocol. It is particularly well suited to the continuous transmission of data

.

UDP

(User Datagram Protocol) is a lightweight, unreliable, datagram-oriented, connectionless protocol. It can be used when reliability isn't important. For example, a server that reports the time of day could choose UDP. If a datagram with the time of day is lost, the client can simply make another request.Slide63

Qt

NetworkingSlide64

Qt QThread

(IPC)

What a thread has:

Instead

of starting in main

()

QThreads

begin

executing

in

run

().

By

default, 

run

()

starts

the

event

loop by calling 

exec

Its own stack pointer, instruction(program counter), processor registers and

execution state

It access to shared resources (shared memory, wait conditions, mutually exclusive data blocks and semaphores) in app’s address spaceSlide65

Qt QThread

(IPC)

Execution ends when you return from 

run() method

By default, 

by calling the exec(),

run(

)

starts the event loop Slide66

Qt QThread

(IPC)

QThread

will

notify

you via a signal when the thread is 

started

(),

finished

(), and 

terminated

(),

Use

 

isFinished

() and 

isRunning

() to query the state of the

thread

,

Use

 

wait

() to block until the thread has finished

exec.Slide67

Qt QThread

(IPC)Slide68

Qt QThread

(IPC)

The

QThread

class provides

platform-independent threads

.

Qt

supports multi-threading and encapsulates threads using

QThread

class

.

Most

QObjects

are thread safe and re-entrant, and can communicate across threads.

Qt

can only can have only one

GUI thread

(

QApplication

)

Any widgets inherited from

QWidget

are not thread safe, but we can use signal and make threads to communicate between the back-end application to the front.

QThreads

begin executing in 

run

() method.

By

default,

run

() starts the event loop by calling 

exec

() and runs a

Qt

event loop inside the thread.Slide69

QThread

Another way to make code run in a separate thread, is to subclass

QThread

and

re-implement

 

run

(). 

QMutex

provides

access serialization between threads

. The purpose of

QMutex

is to protect an object, data structure or section of code so that only one thread can access it at a time

(similar

to the Java synchronized keyword). It is usually best to use a

mutex

with a 

QMutexLocker

since

this makes it easy to ensure that

locking/unlocking

are performed

onsistently

.

QSemaphore

is a generalization of a

mutex

. While a

mutex

can only be locked once, it's possible to acquire a semaphore multiple times. Semaphores are typically used to protect a certain number of identical resources.Slide70

QThread

QtConcurrent

namespace provides high-level APIs that make it possible to write multi-threaded programs without using low-level threading primitives

.

One

important class in this namespace is 

QThreadPool

, a class that manages a pool of threads.

Every

Qt

application has a 

QThreadPool

::

globalInstance

() with a suggested maximum thread count that defaults, on most systems, to the number of cores.

Using 

QtConcurrent

's

functional map/filter/reduce algorithms, which apply functions in parallel to each item in a container, you can write a program that automatically takes advantage of the system's multiple cores by distributing the processing across the threads managed by the thread pool.Slide71

Qt

Resources

File embedded in

Qt

applications and libraries

Accessed with

Qt

file objects and methods

Dynamic file name space

Usually starts with “:” path and file ending with .

qrc

and

qmake

will handle that automatically for you

Benefit: deploy the executable with resourcesSlide72

Qt

Internationalization

Internationalization/Localization (i8

Multi-byte character sets

Translation methods

Unicode support

Using

QString

(support Unicode), and

QChar

(conversion to local character sets)

Context sensitive resources file aliases

Translation tools (string extraction, translation editor)

Wrap all the string in macro “

tr

” and save in .

ts

file

(i.e.

QLabel

label (“

tr

(“username”))

Using

Qt

Linguist (graphical tool table based translation editor)Slide73

Qt

Android

Started to deploy on

Qt

5.x

Originally the Light house project

Two additional tools;

Necessitas

(Lighthouse project deploy to Android)

Ministro

(deployment library to the consumers)

You need Android SDK and NDK installed on your machine

Setup the path in

QtCreator

To deploy use the

Ministro

(deployment service)Slide74

QML and JavaScript

Qt

Quick with QML and you can use JavaScript for engine along C++

Started to be released since late 2009 (

Qt

4.7)

Nokia focused on that for the Symbian/

Meego

phone and future smartphone development

Support on

QtCreator

JavaScript-based declarative Components

Sub classing

QDeclerativeItem