Qobject This class is the core of the Qt object model, and most of the QT classes inherit from this category. The central feature of this model is a mechanism called signals and slots (signal and slots) to communicate between objects, you can connect a signal to another slot through the Connect (...) method, and you can use the disconnect (...) method to disconnect the connection. You can also temporarily block the signal by calling the Blocksignal (...) method,
Qobject organize themselves in the object tree. When you create a qobject and use other objects as the parent object, the object is automatically added to the parent object's children () list. The parent object has this object, for example, it will automatically delete all of its child objects in its destructor. You can find an object by using the Findchild () or Findchildren () function.
Each object has an object name (ObjectName ()) and a class name, which can be obtained by the corresponding MetaObject object. You can also use the Inherits () method to determine whether an object's class inherits from another class.
When the object is deleted, it emits a destroyed () signal. You can capture this signal to avoid invalid references to Qobject.
Qobject can receive events through event () and filter events for other objects. Please refer to Installeventfilter () and EventFilter () for more information.
For each object that implements the signal, slot, and attribute, the Q_object macro must be added.
Qobject has implemented so many functions, so how does it work. Let's use its Source Code to solve the secret.
Qobject class implementation file a total of four, Qobject.h,qobject class basic definition, is also our general definition of a class header file Qobject.cpp,qobject class implementation code is basically in this file Qobjectdefs.h, the most important thing in this file is defining the Qmetaobject class, which is the core of the signal, slot, and properties. Qobject_p.h, the code in this file is an auxiliary implementation of Qobject class, and the most important thing here is to define a Qobjectprivate class to store the member data of the Qojbect object.
Understanding this Qobjectprivate class is also the basis for our understanding of QT Kernel source code, which contains the data members of each QT object, so let's start by understanding Qobject's data storage code first of my QT Kern El Source Code Tour.
Stay tuned for the next section: Qobject Object data storage
====================================
Statement:
The Inside QT Series column is the original technical article of the QT Core Technology Forum (insideqt.com).
This series of columns may be reproduced at will, but this paragraph and the original address of each article must be retained.
Not for commercial use without the consent of the author
"Inside Qt Series" Column Total index:
Http://www.insideqt.com/bbs/viewthread.php?tid=9&extra=page%3D1
Original address of this article:
Http://www.insideqt.com/bbs/viewthread.php?tid=4&extra=page%3D1
====================================