Introduction to qt
This presentation is the property of its rightful owner.
Sponsored Links
1 / 49

Introduction to Qt PowerPoint PPT Presentation


  • 66 Views
  • Uploaded on
  • Presentation posted in: General

Introduction to Qt. Build Great Apps Using Qt Jeff Alstadt. Introduction. My name is Jeff Alstadt I w ork as a Senior Developer at Litholink , a LabCorp company am a passionate C/C++ and .NET developer worked with Qt in 2011 while at Centare

Download Presentation

Introduction to Qt

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Introduction to qt

Introduction to Qt

Build Great Apps Using Qt

Jeff Alstadt


Introduction

Introduction

  • My name is Jeff Alstadt

  • I

    • work as a Senior Developer at Litholink, a LabCorp company

    • am a passionate C/C++ and .NET developer

    • worked with Qt in 2011 while at Centare

    • love open source and believe it is the right way to do software development

    • am an avid technical speaker and blogger


Today we are talking about

Today we are talking about


This is qt 5

This Is Qt 5


What is qt

What is Qt?

Qt is an open source cross platform UI toolkit for the C++ platform

Qt is used by over 500,000 developers

Although digia has taken over support the Qt project, Qt is still a strong contender for embedded Linux (RTOS), desktop UI development (Windows, Mac and Linux), and mobile devices (tablet, phone)


Qt founders

Qt Founders

Qt was founded in 1991 in Oslo, Norway by Erik Chambe-Eng and Haavard Nord

Both Erik and Haavard had founded Trolltech on 4 March 1994.

Trolltech‘s IPO came on the Oslo Stock Exchange in July 2006

In 2001 Qt introduced Qtopia which was an application platform for embedded Linux-based devices such as mobile phones, home media and etc.


Qt founders1

Qt Founders

  • The toolkit was called Qt becuase the letter Q looked appealing in Haavard‘s Emacs font and “t“ was inspired by Xt, the X toolkit


So what does the qt ecosystem look like

So what does the Qt ecosystem look like


But isn t qt dead

But isn’t Qt dead?

Actually not, over 500,000 developers have applications built on Qt technology

Even though Nokia sold Qt to Digia, Digia has promised 15 M Euro investment in Qt research and development and ecosystem activities

Commercial licensing ensures future funding of Qt development

The next Blackberry will be using Qt as its UI framework

Qt mobile apps have been successfully ported to iOSand Android


Digia s goals for qt

Digia’s Goals for Qt

#1 in multi-platform support

#1 in developer experience

#1 in creating great user experiences

Belief in dual licensing model

Strong value generating ecosystem

Open business architecture


But qt can t handle web

But Qt can’t handle web…

Actually Qt is enabled for the web. Using QtWebKitQt developers can develop apps using C++, QML and HTML5/JavaScript.

QtWebKit provides facilities for rendering of HTML, XHTML, SVG, CSS and JavaScript

QtWebKit Bridge provides a bridge between the JavaScript execution environment and the Qt object model.

QtWebkit is based on the Open Source WebKit Engine


Fundamental technologies of qt

Fundamental Technologies of Qt

The Tulip Container Classes

The Arthur Paint System

The Interview Framework

The Scribe Classes

Qt Main Window Classes

Graphics View

Qt Network Module

Resource System

Unit Testing Framework


Qt development tools

Qt Development Tools

Qt Creator – cross platform C++ debugger and developer designed specifically for Qt

Qt Visual Studio add-in – provides Qt integration with Visual Studio 2008, 2010 and 2012

QtSimulator - A fast and lightweight simulator for Qt applications running on Nokia devices.

Eclipse Integration Plugin

QtTeambuilder – distributed C/C++compilation

Qt Mobility – mobile API

Qt SDK

Qt Quick

QtWebkit


Qt lighthouse

Qt Lighthouse

The Qt Lighthouse project was a project started to gain advancement in providing Qt ports to iOS and Android

The Lighthouse project is the project that will allow Qt to be deployed on mobile devices


Qt meets android

Qt Meets Android

  • The Necessitas project is a community driven Lighthouse based port of Qt to Android

  • It has a plugin for Qt Creator to do Android development

  • An installer application for Android called Ministro exists

    • Ministro is responsible for downloading the Qt libraries specific to that Android device


Qt meets ios

Qt Meets iOS

The Qt Lighthouse project was an initiative to get Qt running on the iOS platforms.


Qt overall architecture

Qt Overall Architecture


Let s get technical with qt

Let’s get technical with Qt

  • Here we will get into Qt concepts

    • QObject

    • Meta Object Compiler (MOC)

    • Qt Container Classes

    • Signal Slot System

    • Qt Property System

    • Qt Event System

    • Qt Model View Concept

    • Qt Widgets (QWidget)

    • Qt Graphic View (QGraphicView)


Qobject

QObject

  • Most objects in Qt inherit from QObject

  • This provides your custom Qobject classes to have

    • Signals and slots support

    • Property Support

    • Memory Management Support

    • Introspection


Meta object compiler

Meta Object Compiler

  • A program that handles Qt’s C++ Extensions

  • How it works:

    • Moc looks for the Q_OBJECT macro

      • Once found moc will produce a C++ source file containing the meta-object code that is required for

        • Signals and slot mechanism

        • Run-time type information

        • Dynamic Property System

    • Moc produces another header and source file with the moc_mycppfile.cpp

      • These need to be included in the make file so that the code can be compiled and linked.


Qt container classes

Qt Container Classes

  • Qt utilizes many of the STL collection classes and introduces some of its own

  • These include

    • QList

    • QMap

    • QStack

    • QQueue

    • QSet

    • QHashMap

    • QVector


Signals and slots

Signals and Slots

Specific concept in Qt every Qt developer needs to know

Implements simple Observer Pattern

Type safe

Decoupled

Objects inherited from QObject will only receive the signal notifcations

connect connects the object signal to the respective slot


Signal slot code example

Signal Slot Code Example


Qt property system

Qt Property System

The Qt system provides a means to set any property in the Qt Meta-Object System

The Qt solution works with any standard C++ compiler Qt supportsQ_PROPERTY is a macro that is used to declare property

This declaration must be done inside a QObject


Qt event system

Qt Event System

An event is an object or a set of objects derived from the abstract class QEvent

Events represent things that have happened either within an application or as a result of outside activity that the application needs to know about

Events are recieved and handled by instance of a derived QObject class


Common qt events

Common Qt Events

QResizeEvent (Window Resizing)

QPaintEvent (Window Repainting)

QMouseEvent (Mouse Input)

QKeyEvent (Keyboard Input)

QCloseEvent (Window close)


Sending events

Sending Events

  • In Qt, we can utilize the QCoreApplication to create and send our own custom events.

  • To do this, we utilize sendEvent() and postEvent().

    • sendEvent() processes the event immediatly.

    • postEvent() posts the event on queue for later dispatch When Qt‘s main event loop runs, it will then dispatch all posted events.

  • To create a custom Qt Event type, simpily subclass your event from QEvent and ensure it has an event number that is greater than QEvent::User (1000 presently in 4.8)

  • For all events, check here


Model view

Model View

Qt has an advanced Model View archictecture concept that was inspired from the MVC approach

Instead Qt utilizes a delegate instead of a controller

The delegate is used to provide a fine control over how items are rendered and edited

For Qt specific views, Qt provides the appropriate delegate for that view


Commonly used qt model classes

Commonly Used Qt Model Classes

QStringListModel

QStandardItemModel

QDirModel

QSqlQueryModel

QSqlTableModel

QSqlRelationalTableModel

QSortFilterProxyModel


Graphics view

Graphics View

  • QGraphicsView – a view for fast structured 2D graphics

  • Graphics items known as QGraphicItems are placed in a scene known as QGrahpicsScene

  • A scene is then displayed in one or more views (QGraphicViews)

  • Graphic items can be

    • lines, rectangesl polygons, pixmaps, ellipses, text, SVG drawings, widgets or any customizable item you can think of

    • moved, scaled, rotated


Graphics items

Graphics Items

  • QGraphicsItems are lightweight compared to QWidget

    • This allows for thousands of these guys to exist while not taking a hit on performance or memory

  • QGraphItems can be arbitrarily transformed (QTransform)

    • Support for high quality zooming for example

  • Graphics Items have there own internal event system that is slightly different than the regular QEvent system

  • Widgets can be embedded into a graphics scene by using the QGraphicsProxyWidget


Hello world graphics view example

Hello World Graphics View Example

#include <QtGui>

int main(intargc, char **argv) {

QApplication app(argc, argv);

QGraphicsScenescn;QGraphicsEllipseItem ellipse(-10, -10, 120, 50);scn.addItem(&ellipse);

QGraphicsTextItem text(“Hello World”);

scn.addItem(&text);QGraphicsView view(&scn);view.show();

return app.exec():}


For more about qgraphicview check these videos

For More About QGraphicViewCheck these Videos:

http://qt-project.org/videos/watch/programming_with_qt_qgraphicsview_by_kdab

http://qt-project.org/videos/watch/programming_with_qt_qgraphicsview_by_ics


Internationalization

Internationalization

Qt supports Unicode via QString

Support for Right-to-Left (Chinese)

Read/Write files in different codecs

Layout system can be internationalized

Qt Linguist applications allows apps to be translated easily


To learn more on internationalization see

To learn more on Internationalization see

“Translating Qt Applications” – Benjamin Poulainhttp://qt-project.org/videos/watch/translating_qt_applications


Interprocess communication ipc

Interprocess Communication (IPC)

Shared memory

TCP/UDP Sockets (QSocket)

HTTP/FTP protocol support

D-Bus


Qt state machine framework smf

Qt State Machine Framework (SMF)

  • Introduced in Qt 4.6 and part of QtCore module

  • Originated from Qt-SCXML research project

  • SMF provides the means to create heirarchical finite state machines (HFSMs)

  • SMF also provides an “interpreter” for executing HFSMs

  • Helps to reduce spaghetti code by

    • By making if statements implicit since state is implicit

    • Producing clear control flow


For more learning on qt state machines

For more learning on Qt State Machines

  • State Machine Framework

    • http://www.slideshare.net/qtbynokia/qt-state-machine-framework -Slides

    • http://qt-project.org/videos/watch/state_machine_framework - Video


Unit testing

Unit Testing

  • Qt supports test driven development (TDD)

  • Using QTestLib, Qt developers can do unit tests

  • Qt supports

    • Basic Unit Testing

    • Data Driven Testing

    • Cross-Platform and Cross-Compiler Unit Tests

    • Stand alone unit tests

    • Memory Debugging

    • Integrations


Qt unit test macros

Qt Unit Test Macros

  • QVERIFY

    • Evaluates complex expressions

  • QCOMPARE

    • Compares two values using the respective object comparison operator


Hello world unit test example

Hello World Unit Test Example

class QStringTest : public QObject {

Q_OBJECT

private slots:

void toUpper()

{

QStringstr(“hello world”);

QCOMPARE(str.toUpper(),

Qstring(“HELLO WORLD”));

}

};


Benefits of data driven tests

Benefits of Data Driven Tests

Allows for separation of logic and data

Improved readability

Easily extendable

Reduction of copy and pasting of code in test code

Ease in testing the border cases of the application


Coded ui test support

Coded UI Test Support

QtTestLib offers non-native mouse and keyboard simulation support for QWidgets

Very basic support for replay eventa

3rd party tools such as Squish and KD Executer


Learn more about qt unit testing

Learn more about Qt Unit Testing

Squish - http://qt-project.org/wiki/Category:Tools::Squish

Unit Testing in Qt Applications by HaraldFernengelhttp://qt-project.org/videos/watch/unit_testing_in_qt_applications


Performance

Performance

  • Qt provides QBENCHMARK to measure code

  • QBENCHMARK measures code based on

    • Walltime (default)

    • CPU Tick Count (-tickcounter)

    • Valgrind/Callgrind (-callgrind)

    • Event counter (-eventcounter)


Theory of constraints

Theory of Constraints

  • TOC was developed by Eliyahu M. Goldratt

  • Basically TOC is a theory which says that given a complex system, there is usually one aspect of that system that will limits it ability to achieve its goal or optimal functioning. Before an achievement of any significant improvement of the system can be achieved, the constraint or bottleneck must be first identified and resolved

    • Reduce Bottlenecks improve Performance


Qt optimization techniques

Qt Optimization Techniques

  • Choose the right container

  • Utilize implicit data sharing efficiently

    • ExampleObject obj0;Object obj1, obj2, obj3 = obj0

      • Here data is only copied if some other guy modifies it since Object 1 will have deep copy of object ObjectData and Object 2 and Object 3 will only have shallow copies

    • Avoid deep-copy, its expensive

      • Pass objects around as const references

      • Only use const operators and functions if possible

  • Avoid bottlenecks


To learn more about optimizing your qt apps check

To learn more about Optimizing your Qt Apps check

Optimizing Performance in QtBased Applications - Bjørn Erik Nilsenhttp://www.slideshare.net/qtbynokia/optimizing-performance-in-qtbased-applications


Thanks

Thanks


  • Login