当前位置:网站首页>QT smart pointer error prone point
QT smart pointer error prone point
2022-07-25 23:48:00 【StephenQin】
- Qt The method of dynamic conversion between smart pointers in is qSharedPointerDynamicCast, Using this method does not increase the reference count .
- take this When the pointer is converted into a smart pointer , Can't use QSharedPointer(this) This way, , Instead, use sharedFromThis() This kind of method .
- Construction and type conversion are easy to make mistakes :
Code of non smart pointer :
Base *p = new Derived();
Error conversion writing of smart pointer :
// Wrong writing 1
QSharedPointer<Base> p(new Derived);
// Wrong writing 2
QSharedPointer<Base> p = QSharedPointer<Base>(new Derived);
// Write it correctly :
QSharedPointer<Base> p = QSharedPointer<Derived>(new Derived);
// Ensure that the types are consistent when constructing , The work of type conversion is left to ”=”.
边栏推荐
- S4/hana mm & SD EDI Nast based integrated configuration (orders, ordrsp, desadv, invoice)
- Leetcode 0919. complete binary tree inserter: array representation of complete binary tree
- 《数据密集型应用系统设计》 - 应用系统概览
- 意向不到的Dubug妙招
- 2022 Niuke multi School Game 2
- Macro task, micro task and event cycle mechanism
- chown: changing ownership of ‘/var/lib/mysql/‘: Operation not permitted
- Qt风格(QSS)应用之QProgressBar
- 热部署和热加载有什么区别?
- Strategy mode_
猜你喜欢
![[code case] blog page design (with complete source code)](/img/9e/0e7cab956515b9cc75a7567eb477d2.png)
[code case] blog page design (with complete source code)

Storage of data in memory

Bubble sort idea and Implementation

Payment terms in SAP message No. vg202 IDoc e1edk18 have been transferred: check data

Loading process such as reflection

initializer_list工具库学习

S4/hana mm & SD EDI Nast based integrated configuration (orders, ordrsp, desadv, invoice)

Query commodity cases (operate data with array addition method) / key points

chown: changing ownership of ‘/var/lib/mysql/‘: Operation not permitted

Docker 安装 Redis-5.0.12(远程访问)
随机推荐
Recursion of function (use recursion to find the factorial of 1-N) (use recursion to find Fibonacci sequence) (use recursion to traverse data)
[JUC] concurrent keyword volatile
S4/HANA ME21N创建PO 输出控制消息按钮丢失解决方法(切换EDI 输出模式BRF+至NAST模式)
The process of finding free screen recording software - I didn't expect win10 to come with this function
initializer_list工具库学习
[learning notes] unreal 4 engine introduction (IV)
TS union type
Duplicate numbers in array
C# - readonly 和 const 关键字
Anti shake and throttling
S4/HANA MM & SD EDI基于NAST的集成配置(ORDERS, ORDRSP, DESADV, INVOIC)
TS interface
[code case] blog page design (with complete source code)
[nodejs] nodejs create a simple server
ratio学习之ratio_add,ratio_subtract,ratio_multiply,ratio_divide的使用
Static agent + dynamic agent
Moment.js
Practical skills of easyexcel
面试重点——传输层的TCP协议
Release of v6.5.1/2/3 series of versions of Xingyun housekeeper: the ability of database OpenAPI continues to be strengthened