当前位置:网站首页>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 .
边栏推荐
- Hyperautomation for the enhancement of automation in industries
- How to design a high concurrency system?
- Idea settings ignore file configuration when submitting SVN
- Wangeditor rich text editor
- 金鱼哥RHCA回忆录:CL210管理存储--对象存储
- Paddlenlp's UIE relationship extraction model [executive relationship extraction as an example]
- Save the image with gaussdb (for redis), and the recommended business can easily reduce the cost by 60%
- OverTheWire-Bandit
- Basic theory of monocular depth estimation and paper learning summary
- Depth estimation self-monitoring model monodepth2 paper summary and source code analysis [theoretical part]
猜你喜欢
![[eloquence] negotiation persuasion skills and Strategies](/img/01/0fcbbfcf35a6d166c14ba4215eacac.jpg)
[eloquence] negotiation persuasion skills and Strategies

机械制造业数字化新“引擎”供应链协同管理系统助力企业精细化管理迈上新台阶

基于PaddleOCR开发uni-app离线身份证识别插件

Digital Twins - cognition

Resource not found: rgbd_launch 解决方案

苹果官网产品打折 买iPhone 13 Pro Max 可省600元
![einsum(): operands do not broadcast with remapped shapes [original->remapped]: [1, 144, 20, 17]->[1,](/img/bb/0fd0fdb7537090829f3d8df25aa59b.png)
einsum(): operands do not broadcast with remapped shapes [original->remapped]: [1, 144, 20, 17]->[1,

swiper 一侧或两侧露出一小部分

【口才】谈判说服技巧及策略

Save the image with gaussdb (for redis), and the recommended business can easily reduce the cost by 60%
随机推荐
How to make a set of code fit all kinds of screens perfectly?
maya建模练习
基于浏览器的分屏阅读
Realize a family security and environmental monitoring system (II)
[directory blasting tool] information collection stage: robots.txt, Yujian, dirsearch, dirb, gobuster
Gartner 2022 top technology trend: Super automation
VS2017大型工厂ERP管理系统源码 工厂通用ERP源码
金鱼哥RHCA回忆录:CL210管理存储--管理共享文件系统
pt100测温电路图(ad590典型的测温电路)
Goldfish rhca memoirs: cl210 management storage -- object storage
Reverse Integer
Day1: 130 questions in three languages
Idea regular expression replacement (idea regular search)
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)
手把手教你申请SSL证书
Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]
牛客多校 E G J L
网络安全应急响应技术实战指南(奇安信)
PT100 temperature measurement circuit diagram (AD590 typical temperature measurement circuit)
51单片机学习笔记(1)