Qt Qobject Basics
Objectives
- Understand the fundamentals of QObject
- Be able to use Qt properties and other core features provided by the Qt's meta-type system
QObject
- QObject Class Reference
- Heart of Qt's object model
- Base class for all object classes
- Central location for the most important concepts in Qt such as qt signal and slots |signal and slots
Three major responsibilities
- Memory Management
- Introspection (runtime identification of object types)
- Event handling
Parent Child Relationship
- Each QObject instance may take a parent argument.
- Child informs its parent about its existence and the parent adds it to its own list of children.
- If a widget objects does not have a parent, it is a window.
- The parent can do the following:
- Hide/show children when hiding/showing.
- enables/disables children when enabled/disabled
Qt Property System
- Qt property system is based on the Meta-Object System.
- To declare a property use the Q_PROPERTY() macro in a class that inherits QObject.
Additional Features of a Property
- A READ accessor function is required. It is for reading the property value.
- A WRITE accessor function is optional. It is for setting the property value. It must return void and must take exactly one argument, either of the property's type or a pointer or reference to that type.
- A RESET function is optional. It is for setting the property back to its context specific default value.
- A NOTIFY signal is optional. If defined, it should specify one existing signal in that class that is emitted whenever the value of the property changes.
- The DESIGNABLE attribute indicates whether the property should be visible in the property editor of GUI design tool (e.g., Qt Designer).
- The SCRIPTABLE attribute indicates whether this property should be accessible by a scripting engine (default true).
- The STORED attribute indicates whether the property should be thought of as existing on its own or as depending on other values.
- The USER attribute indicates whether the property is designated as the user-facing or user-editable property for the class.
- The presence of the CONSTANT attibute indicates that the property value is constant.
- The presence of the FINAL attribute indicates that the property will not be overridden by a derived class.





