cpp-2013 #18 qt part 2

8
Advanced Qt Qt Creator IDE Signals/Slots mechanism Qt meta-system Parent/child ownership Copy-on-write Bonus

Upload: eleks-developers-courses-if

Post on 19-May-2015

2.454 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: cpp-2013 #18 Qt Part 2

Advanced Qt

• Qt Creator IDE• Signals/Slots mechanism• Qt meta-system• Parent/child ownership• Copy-on-write• Bonus

Page 2: cpp-2013 #18 Qt Part 2

Qt Creator IDE - native IDE for Qt• free, open-source and cross-platform• full development cycle out of the box• QtWidget and QtQuick WYSIWYG design tools• fast but multifunctional• VCS integration support• debugging and profiling• project management• Qt help integration• powerful code editor• examples and tutorials• build configuration and

management

Page 3: cpp-2013 #18 Qt Part 2

QObject and QWidget

QObject - central class in Qt• base for most Qt classes• handles signals/slots• keeps meta-data• handles parent/child ownership

QWidget - base for all UI classes• handles widgets positioning• any widget can be a separate window• handles UI events (mouse, keyboard etc)• can be simply ported to any platform thanks to Lighthouse

Page 4: cpp-2013 #18 Qt Part 2

Parent/child ownership

The problem:• make complex object's lifetime control transparent for

developer• prevent memory leaks and referencing deleted objects• prevent removing button while windows still visible

The solution:• each QObject may have a parent QObject• parent object knows its children and vice-versa• parent removes its children• parent widget draws its children inside itself

Page 5: cpp-2013 #18 Qt Part 2

Copy-on-write

The problem:• containers copying is usually expensive• working with pointers is inconvenient• working with const references decreases readability

The solution:• many Qt classes share internal data between object

copies• as soon as some object is changed, internal data are

copied to prevent changing all objects

Page 6: cpp-2013 #18 Qt Part 2

Signals/slots• QObjects may emit signals• QObject's void method may be marked as slots• Signals and slots may be connected many-to-many.

Benefits:• simple way of communication between objects• objects don't know about each other (no interfaces)• perfectly works in multithreading application• slot call can be queued for async execution • connections can be easily managed in run-time• no configuration needed, just subclass QObject• works across C++, Javascript, QML

Page 7: cpp-2013 #18 Qt Part 2

Qt meta-system• powered by MOC• stores information about QObject memebers• provides a way to call object method by name• empowers signals/slots mechanism• available via QMetaObject, QMetaProperty,

QMetaMethod, QMetaEnum classes• empowers Javascript, QML, plugins• make it possible to have WYSIWYG designer• highly extensible

Page 8: cpp-2013 #18 Qt Part 2

Out of scope• Model/View architecture in Qt• Styling Qt applications• Animation in Qt applications• Qt Javascript engine• Qt plugins system• New Qt ports coming: WinRT, Android, iOS• Bindings: PyQt, RubyQt, Qt Jambi and more...• Mobile programming• Declarative programming with QtQuick