1.7k likes | 2.74k Views
Qt Framework. Qt History Who uses Qt Benefits Tools and components SDK Core Internals Programming with Qt. Programming with Qt. - Containers (Tulips) - 2D/3D graphics - Widgets - Graphics View - XML - Thread/IPC
E N D
Qt Framework Qt History Who uses Qt Benefits Tools and components SDK Core Internals Programming with Qt
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 iOS
Qt Framework Qt History Who uses Qt Benefits Tools and components SDK Core Internals Programming with Qt
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.
Qt History Qt Was initially developed by two persons,Haavard Nord (CEO), and EirikChambe(President) in early 90. Both 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 source
QtHistory Traditional 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 Qwt6.1 (latest version) Rich set of Widgets (1000+), Qwt (125+) classes Very Good Documentation, help, and examples QtProject: http://www.qt-project.org DigiaSite: http://qt.digia.com
Qt Framework Qt History Who uses Qt Benefits Tools and components SDK Core Internals Programming with Qt
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, …
Qt Framework Qt History Who uses Qt Benefits Tools and components SDK Core Internals Programming with Qt
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 boundary
Qt Framework Qt History Who uses Qt Benefits Tools and components SDK Core Internals Programming with Qt
Tools Qt Creator : Cross platform IDE Qt Designer: GUI layout and forms builder QtLinguest: Internationalization toolset Qt Assist: Customizable documentation reader QtQmake: 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++ library
Building Qt Application (Qmake) Qmake : Creates Qt Project file (.pro) , can 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 rcc
Qt Framework Qt History Who uses Qt Benefits Tools and components SDK Core Internals Programming with Qt
Qt SDK The Qt class library encompasses all the functions needed build robust, high end applications, and they can be separate 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 WebKitFramework Phonon Framework
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: Set of customizable widgets, 2D graphics canvas and OpenGL® integration, powerful font and layout engine style engine and widget style sheets, anti-aliasing, vector deformation, and SVG support, advanced graphics effects support for ARGB top-level widgets
Qt Framework Qt History Who uses Qt Benefits Tools and components SDK Core Internals Programming with Qt
Core Internals Object Model Meta Object System Property System Signal and Slots State Machine Framework Timers
Core Internals Object Model Meta Object System Property System Signal and Slots Event System
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. Qtprovides 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.
Core Internals Object Model Meta Object System Property System Signal and Slots Event System
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 automatically
Core Internals Object Model Meta Object System Property System Signal and Slots State Machine Framework Timers
Property Systems Provides a sophisticated property system Does not rely on non-standard compiler features like __property or [property]. Works withany standard C++ compiler on every platform Qt supports. To declare a property, use theQ_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])
Property Systems Keep 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 priorityREAD, priority WRITE, setPriorityNOTIFY priorityChanged) Q_ENUMS(Priority)
Core Internals Object Model Meta Object System Property System Signal and Slots Event System
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.
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
Signals and Slots Same type, and number of parameters 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)
Signals A signal is a way to inform a possible observer something of interest has happened inside the observed class A PushButton clicked (an asynchronous 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”) )
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)
Core Internals Object Model Meta Object System Property System Signal and Slots Event System
Event Systems Eventsare objects, derived from abstract QEvent class, usually receives from window system and dispatch it to widgets. When an event occurs, QtCreates 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;
How Events are Delivered When an event occurs, QtCreates an event object (an instance of the QEvent), Delivers 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;
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, QResizeEventaddssize()
Concepts in Qt Widgets Application Main Window Desktop Integration Dialog Windows Layout Management Model/View Programming
Application Main Window Classes 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.
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.
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 …
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”; Qstringfullname = first + “ “+ last; Qstring fullname2 = Qstring(“%1 %2).arg(first).arg(last)); Translation: QstringtranslatedSend = tr(“Send”);
Qt Strings Splitting/Joining on a delimiter character QString numbers = “1, 2,3,4,45,6,23”; QStringListnums = numbers.split(‘,’); int sum=0; foreach(Qstringnum, numberList) Sum +=num.toInt(); Removing leading or trailing whitespace: QString name = “ Joe Doe”; QStringtrimedName = name.trimmed();
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 3kinds 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.
Add headers Add in private section Model/View Programming (2)