qsharedpointer

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

Using QSharedPointer with new[] yields “Mismatched free() / delete / delete[]” in valgrind

我是研究僧i 提交于 2019-11-29 14:49:11
I have the following code: QPair<QSharedPointer<unsigned int>, int> someclass::somefunction() { int siz = data_size(); QSharedPointer<unsigned int> buffer(new unsigned int[siz]); // Fill the buffer... return qMakePair(buffer, siz); } At some point, the QSharedPointer returned by this function will go out of scope and the pointer set in the constructor will be free'd. Using valgrind 3.6.1, I get a "Mismatched free() / delete / delete[]" error. Is there anything wrong with my use of QSharedPointer or do I just have to live with this valgrind warning? One way to fix this is to write a custom