当前位置:网站首页>QObject source code analysis -d pointer and Q pointer
QObject source code analysis -d pointer and Q pointer
2022-07-25 14:25:00 【vegetablesssss】
have a look QObject Source code :
class Q_CORE_EXPORT QObject
{
...
protected:
QScopedPointer<QObjectData> d_ptr;
...
}
You can see QObject There is one protected member d_ptr, The type of QObjcetData,QScopedPointer Be similar to unique_ptr, have a look QObjectData Source code :
class Q_CORE_EXPORT QObjectData {
public:
virtual ~QObjectData() = 0;
QObject *q_ptr;
....
};
above d_ptr and q_ptr Namely d Pointers and q The pointer
have a look QObject Constructors :
QObject::QObject(QObject *parent)
: d_ptr(new QObjectPrivate)
{
Q_D(QObject);
d_ptr->q_ptr = this;
....
}
You can see ,QObject Give it during construction d_ptr assignment QObjectPrivate, Look at the source code :
class Q_CORE_EXPORT QObjectPrivate : public QObjectData
{
...
}
You can see QObjectPrivate by QObjectData Subclasses of , from QObject You can see that ,QObject and QObjectPrivate Have each other's object pointers , that QObject Why do that ?
actually QObject All member variables of are placed in QObjectPrivate in , Why put member variables in QObjectPrivate And then in QObject Use in D The pointer d_ptr Well ? In fact, it is to solve the problems of compilation and dependency .
- Compilation problems : If there is 20 individual cpp file #include 了 qobject.h file , So once you get to this .h The data member variables of the file are slightly modified , This will happen the next time the project is compiled 10 individual cpp All files must be recompiled . This is the disadvantage of directly defining the data member variables of the type in the type itself .
- The second is dependency . Generally will dll When provided for use by others , It must also contain the corresponding header file , If it changes at this time QObject.h Members of , After modifying the data member variables of a type , This will cause the memory layout of object instances of type to change , Then all use this dll Must be recompiled to use , Instead of simply replacing the previous dll Just go . Save data members with pointers , Put the implementation of this pointer in cpp Can avoid header file changes , So as to directly use the new dll You don't have to use this dll All the places are recompiled .
Actually q Pointers and d Programming skills for pointer utilization c++ PIMPL, If you are interested, you can find relevant information .
边栏推荐
- PHP website design ideas
- NAT/NAPT地址转换(内外网通信)技术详解【华为eNSP】
- From fish eye to look around to multi task King bombing -- a review of Valeo's classic articles on visual depth estimation (from fisheyedistancenet to omnidet) (Part I)
- 实现一个家庭安防与环境监测系统(二)
- Detailed explanation of how R language converts large Excel files into DTA format
- CDA level1 multi topic selection
- pt100测温电路图(ad590典型的测温电路)
- ~4.1 sword finger offer 05. replace spaces
- Doris学习笔记之与其他系统集成
- That day, I installed a database for my sister... Just help her sort out another shortcut
猜你喜欢

PS制作加载GIF图片教程
知名手写笔记软件 招 CTO·坐标深圳
![[directory blasting tool] information collection stage: robots.txt, Yujian, dirsearch, dirb, gobuster](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[directory blasting tool] information collection stage: robots.txt, Yujian, dirsearch, dirb, gobuster

Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction
![优质数对的数目[位运算特点+抽象能力考察+分组快速统计]](/img/c9/8f8f0934111f7ae8f8abd656d92f12.png)
优质数对的数目[位运算特点+抽象能力考察+分组快速统计]

元器件采购系统的主要功能,数字化采购助力元器件企业飞速发展

PHP website design ideas

Realsense-Ros安装配置介绍与问题解决

Word set paste to retain only text

sudo rosdep init Error ROS安装问题解决方案
随机推荐
CDA level1 double disk summary
Idea error failed to determine a suitable driver class
Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]
Realize a family security and environmental monitoring system (I)
Educational Codeforces Round 132 (Rated for Div. 2) C,D+AC自动机
知名手写笔记软件 招 CTO·坐标深圳
Thymeleaf controls whether display is displayed through style
Hyperautomation for the enhancement of automation in industries
Keys and scan based on redis delete keys with TTL -1
telnet远程登录aaa模式详解【华为eNSP】
手把手教你申请SSL证书
Idea settings ignore file configuration when submitting SVN
Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction
How to make a set of code fit all kinds of screens perfectly?
Pytorch training code writing skills, dataloader, Einstein logo
Detailed explanation of nat/napt address translation (internal and external network communication) technology [Huawei ENSP]
Realize a family security and environmental monitoring system (II)
Opencv video tracking "suggestions collection"
Resource not found: rgbd_launch 解决方案
[directory blasting tool] information collection stage: robots.txt, Yujian, dirsearch, dirb, gobuster