Problem Description:
In the previous article, I wrote that I suggested that it is best to use the QPointer template class when creating a new pointer in the function, so that you don’t need to add the detele pointer clearing operation later. At that time, I felt that the reason for using QPointer was mainly that the two classes QScopedPointer and QSharedPointer were too long and laborious to write. So I think QPointer is pretty good.
However, I saw that the official Qt developer suggested that we abandon QPointer, so I re-understood what was going on...
Solution:
Why is QPointer deprecated?
First, let's take a look at the introduction of these smart pointers:
smart pointer class name | definition | effect |
QSharedPointer | QSharedPointer class Holds a strong reference to the shared pointer |
QSharedPointer is an automatic shared pointer in C++. It behaves exactly like an ordinary pointer for normal purposes, including for constants. A QSharedPointer will delete the pointer it holds when it goes out of scope if no other QSharedPointer objects refer to it. can be changed from normal |