qpointer

Is there a smart pointer that is automatically nulled when its target is destroyed in C++

前提是你 提交于 2019-12-23 12:37:19
问题 I've found QPointer. Are there any others? 回答1: Boost - the weak_ptr has some nice features that make it safe to use, if you are also using shared_ptr . You keep a weak_ptr reference to an instance that is managed by shared_ptr lifetime. When you need to use the underlying instance, convert it to a shared_ptr instance using the constructor of the shared_ptr class, or the lock method. The operation will fail if the underlying instance was deleted. The use is thread safe in the same fashion as

What is the difference between QPointer, QSharedPointer and QWeakPointer classes in Qt?

℡╲_俬逩灬. 提交于 2019-12-03 05:38:36
问题 I have read from the Qt documentations about QPointer , QSharedPointer and QWeakPointer classes. It says: QPointer is a template class that provides guarded pointers to Qt objects and behaves like a normal C++ pointer except that it is automatically set to 0 when the referenced object is destroyed and no "dangling pointers" are produced. QSharedPointer class holds a strong reference to a shared pointer. QWeakPointer class holds a weak reference to a shared pointer. My questions is "What is

What is the difference between QPointer, QSharedPointer and QWeakPointer classes in Qt?

元气小坏坏 提交于 2019-12-02 19:08:32
I have read from the Qt documentations about QPointer , QSharedPointer and QWeakPointer classes. It says: QPointer is a template class that provides guarded pointers to Qt objects and behaves like a normal C++ pointer except that it is automatically set to 0 when the referenced object is destroyed and no "dangling pointers" are produced. QSharedPointer class holds a strong reference to a shared pointer. QWeakPointer class holds a weak reference to a shared pointer. My questions is "What is the difference between these classes?". i.e what is the difference between a pointer to an object and a