1. QObject class, qobject
Brief Introduction
The QObject class is the base class of all Qt objects.
QObject is the core of the Qt object model. The core feature of this model is the object communication mechanism of signals and slots. You can use connect () to connect the signal to the slot and use disconnect () to terminate the connection. To avoid endless signal loops, you can call blockSignals () to terminate the object's signal transmission. Protection Type Functions connectNotify () and disconnectnotifnotify () can trace connections. The QObjects object is organized in the tree structure. When you create a QObject object and use another object as the parent object, the object is automatically added to the children () List of the parent object. The parent class object has the ownership of the subclass object, that is, it will automatically delete the subclass object in the destructor. You can use the findChild () or findChildren () function to find objects by name or type. Each object has an objectName (). The class name of the object can also be obtained through metaObject: className. You can use the inherits () function to determine whether an object inherits from another class. When an object is deleted, it sends a destroy () signal. You can capture this signal to avoid references to null pointers.
QObjects can receive events through event () or filter events of other objects. For more information, see installEventFilter () and eventFilter ().
The event is passed in the thread where the object is created. Note that for qobjects without thread affinity (thread () returns zero), no event processing is executed. Use the moveToThread () function to change the thread affinity of the object and its sub-objects (if the object has a parent object, it cannot be moved ).
Note that the Q_OBJECT macro is required for implementing the signal and slot mechanism or dynamic object attributes. You need to run the metabase compiler on the source file. We strongly recommend that you use this macro in all subclasses of QObject. Whether or not the signal and slot mechanisms are used, this avoids some strange behavior.
All Qt widgets inherit from QObject. A convenient function isWidgetType () returns whether an object is a Widget. It is much faster than qobject_cast <QWidget *> (obj) or obj-> inherits.
Private attributes
ObjectName: QString indicates the object name. You can use objectName () to obtain and setObjectName () to set the object name.