1 / 49

Introduction to Qt

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

gyula
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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Qt Build Great Apps Using Qt Jeff Alstadt

  2. 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

  3. Today we are talking about

  4. This Is Qt 5

  5. 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)

  6. 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.

  7. 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

  8. So what does the Qt ecosystem look like

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

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

  17. Qt Overall Architecture

  18. 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)

  19. 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

  20. 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.

  21. 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

  22. 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

  23. Signal Slot Code Example

  24. 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

  25. 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

  26. Common Qt Events QResizeEvent (Window Resizing) QPaintEvent (Window Repainting) QMouseEvent (Mouse Input) QKeyEvent (Keyboard Input) QCloseEvent (Window close)

  27. 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

  28. 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

  29. Commonly Used Qt Model Classes QStringListModel QStandardItemModel QDirModel QSqlQueryModel QSqlTableModel QSqlRelationalTableModel QSortFilterProxyModel

  30. 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

  31. 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

  32. 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():}

  33. 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

  34. 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

  35. To learn more on Internationalization see “Translating Qt Applications” – Benjamin Poulainhttp://qt-project.org/videos/watch/translating_qt_applications

  36. Interprocess Communication (IPC) Shared memory TCP/UDP Sockets (QSocket) HTTP/FTP protocol support D-Bus

  37. 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

  38. 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

  39. 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

  40. Qt Unit Test Macros • QVERIFY • Evaluates complex expressions • QCOMPARE • Compares two values using the respective object comparison operator

  41. Hello World Unit Test Example class QStringTest : public QObject { Q_OBJECT private slots: void toUpper() { QStringstr(“hello world”); QCOMPARE(str.toUpper(), Qstring(“HELLO WORLD”)); } };

  42. 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

  43. 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

  44. 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

  45. Performance • Qt provides QBENCHMARK to measure code • QBENCHMARK measures code based on • Walltime (default) • CPU Tick Count (-tickcounter) • Valgrind/Callgrind (-callgrind) • Event counter (-eventcounter)

  46. 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

  47. 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

  48. 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

  49. Thanks

More Related