1 / 18

L8: Qt4 Concept

L8: Qt4 Concept. Qt Module QObject QObject Model Signal and Slot Qt Event Loop. Qt Modules. The main five Qt 4 modules are Core: QObject, QThread, QFile, etc. GUI: all classes derived from QWidget, and some related classes XML for parsing and serializing XML

sabin
Download Presentation

L8: Qt4 Concept

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. L8: Qt4 Concept • Qt Module • QObject • QObject Model • Signal and Slot • Qt Event Loop

  2. Qt Modules • The main five Qt 4 modules are • Core: QObject, QThread, QFile, etc. • GUI: all classes derived from QWidget, and some related classes • XML for parsing and serializing XML • SQL for communicating with SQL databases • NET for communicating data between hosts on specific protocols.

  3. Qt Object (I) • The base class of all Qt objects. • Its class name can be found via the corresponding QmetaObject::className(). • Has a unique QObject::objectName(). • Has a location in an object hierarchy. • Can be connected to other Qt Objects to emit signals to them or to receive • signals emitted by them. • Can have new properties added to it at runtime that are not declared in the C++ • class. • Q_OBJECT macro is mandatory for any object that implements signals, slots or • properties.

  4. Qt Objects (II) • Qt Objects should be treated as identities, not as values. Identities are cloned, not copied or assigned, and cloning an identity is a more complex operation than copying or assigning a value. • Therefore, QObject and all subclasses of QObject (direct or indirect) have their copy constructor and assignment operator disabled.

  5. Qt Object Model (I) Qt Object Model adds these features to C++: A mechanism for seamless object communication called signals and slots. Queryable and designable object properties. Event filters. Contextual string translation for internationalization.

  6. Qt Object Model (II) • Qt Object Model adds these features to C++: • Interval driven timers that make it possible to integrate many tasks in an event-driven GUI. • Hierarchical and queryable object trees that organize object ownership in a natural way. • Quarded pointers (QPointer) that are automatically set to 0 when the referenced object is destroyed. • A dynamic cast that works across library boundaries.

  7. Signal and Slot (I) A mechanism for communication between objects A signal is emitted when a particular event occurs. A slot is a function that is called in response to a particular signal.

  8. Signal and Slot (II) • The signals and slots mechanism is type safe: the signature of a signal must match the signature of the receiving slot. • A slot may have a shorter signature than the signal it receives because it can ignore extra arguments. • Since the signatures are compatible, the compiler can detect type mismatches.

  9. Signal and Slot (III) • Signals and slots are loosely coupled: a class which emits a signal neither knows nor cares which slots receive the signal. • More than one signal can be connected to a single slot, and a signal can be connected to many slots (many-to-many). • It is even possible to connect a signal directly to another signal. (This will emit the second signal immediately whenever the first is emitted.)

  10. Example: Diagram Object A emits a signal. A slot in object B is called in response to this signal.

  11. Example: Header (I)

  12. Example: Header (II)

  13. Example: Source

  14. Example: Main

  15. Qt Event Loop: Basic Concept • QEvent encapsulates the notion of an event. • QEvent is the superclass of several specific event classes such as QActionEvent, QFileOpenEvent, QMouseEvent, etc. • QEvent objects can be created by the window system in response to actions of the user (e.g., QMouseEvent), at specified time intervals (QTimerEvent), or explicitly by an application program.

  16. Qt Event Loop: Basic Concept • An event loop is a program structure that permits events to be prioritized, enqueued, and dispatched to objects. • The event loop generally continues running until a terminating event occurs (e.g., the user clicks on Quit).

  17. Qt Event Loop: The Crowd Goes Wild • A Qt program creates objects, connects them, and then tells the application to exec(). At that point, the objects can send information to each other in a variety of ways. • QWidgets send QEvents to other QObjects in response to user actions such as mouse clicks and keyboard events. • A widget can also respond to events from the window manager such as repaints, resizes, or close events. • QObjects can transmit information to one another by means of signals and slots.

  18. References • Qt.Nokia (2011). Qt Reference Documentation [Online]. Available from: http://doc.qt.nokia.com/4.7/index.html [Accessed: 22 January 2011] • Ezust, A. & Ezust, P. (2006). An Introduction to Design Patterns in C++ with Qt 4. (1st ed.). New York: Prentice Hall. • Blanchette, J. & Summerfield, M. (2008). C++ GUI Programming with Qt 4. (2nd ed.). New York: Prentice Hall.

More Related