Inside Qt Series (i): Let's go, starting from the Qobject

Source: Internet
Author: User
Tags object model

Inside Qt Series (i): Let's go, starting from the Qobject

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.


the Qobject class implements a total of four files:
* The basic definition of Qobject.h,qobject class is also a header file that we generally define a class
* Qobject.cpp,qobject Class implementation code is basically in this file
* Qobjectdefs.h, the most important thing in this file is to define 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, the most important thing here is to define a Qobjectprivate class to store the Qojbect object's member data.


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.
The author retains the copyright and may not use it for any commercial purpose without the consent of the author

"Inside Qt Series" Column Total index:
Http://www.insideqt.com/bbs/viewthread.php?tid=9
Original address of this article:
Http://www.insideqt.com/bbs/viewthread.php?tid=4

Previous article:Inside QT Series: Preface
Http://www.insideqt.com/bbs/viewthread.php?tid=3
Next post:Object Data Storage (A)
Http://www.insideqt.com/bbs/viewthread.php?tid=5
====================================
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.