qsharedpointer

Difference between QSharedPointer::isNull() and operator!()

醉酒当歌 提交于 2020-02-03 16:27:42
问题 in Qt docs we read: bool QSharedPointer::operator! () const Returns true if this object is null. This function is suitable for use in if-constructs, like: if (!sharedptr) { ... } and bool QSharedPointer::isNull () const Returns true if this object is holding a reference to a null pointer. What is the difference between these two functions? This is clear what is reference to a null pointer, but what means here "if the object is null" ? What determines if QSharedPointer is null ? How do these

Difference between QSharedPointer::isNull() and operator!()

梦想与她 提交于 2020-02-03 16:25:07
问题 in Qt docs we read: bool QSharedPointer::operator! () const Returns true if this object is null. This function is suitable for use in if-constructs, like: if (!sharedptr) { ... } and bool QSharedPointer::isNull () const Returns true if this object is holding a reference to a null pointer. What is the difference between these two functions? This is clear what is reference to a null pointer, but what means here "if the object is null" ? What determines if QSharedPointer is null ? How do these

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

◇◆丶佛笑我妖孽 提交于 2020-01-20 08:14:25
问题 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 and QObject::deleteLater

旧时模样 提交于 2019-12-22 04:13:07
问题 I have a situation where a QSharedPointer managed object signalizes that it has finished it's purpose and is ready for deletion soon (after execution left the function emitting my readyForDeletion signal). When working with normal pointers, I'd just call QObject::deleteLater on the object, however this isn't possible with a QSharedPointer -managed instance. My workaround is the following: template<typename T> class QSharedPointerContainer : public QObject { QSharedPointer<T> m_pSharedObj;

QSharedPointer and QObject::deleteLater

◇◆丶佛笑我妖孽 提交于 2019-12-22 04:13:04
问题 I have a situation where a QSharedPointer managed object signalizes that it has finished it's purpose and is ready for deletion soon (after execution left the function emitting my readyForDeletion signal). When working with normal pointers, I'd just call QObject::deleteLater on the object, however this isn't possible with a QSharedPointer -managed instance. My workaround is the following: template<typename T> class QSharedPointerContainer : public QObject { QSharedPointer<T> m_pSharedObj;

What is the cost of calling member function via shared pointer?

跟風遠走 提交于 2019-12-13 05:11:11
问题 It is often stated that dereferencing a smart pointer does not have notable performance impacts. (For example here: C Smart Pointer Performance) I am now wondering if this is really true. I understand that it could be, if operations on the object referenced are atomic. Thinking of code based on this snippets: class Worker { [...] public: void setDataProvider( shared_ptr<DataProvider> p ) { m_provider = p; } void doWork() { [...] for(;;) { int d = m_provider->getSomeData(); [ do something with

Attaching signals and slots to an object within a QSharedPointer

…衆ロ難τιáo~ 提交于 2019-12-12 07:58:11
问题 My application contained several functions like this: void SomeClass::set_data_provider(DataProvider *data_provider) { connect(data_provider, SIGNAL(data_available(int)), this, SLOT(data_available(int))); } To avoid passing raw pointers around I have changed all occurrences of DataProvider * to QSharedPointer<DataProvider> . The latter is almost a drop-in replacement for the former, except that you can’t pass a QSharedPointer to QObject::connect . I worked around this by extracting a raw

QCache and QSharedPointer

 ̄綄美尐妖づ 提交于 2019-12-10 10:25:58
问题 The problem is, that I have a QVector of QSharedPointer and I want to put part of them to my QCache . How can I insert a shared pointer to QCache ? What happens if I set the pointer to my cache but destroy the QVector and the shared pointer in it? Will the memory be released and my cache points to nowhere? 回答1: It is a bug if you put just a pointer to your item to QChache and at the same time such pointer is managed by QSharedPointer . The item object can be destroyed by QSharedPointer

QCache and QSharedPointer

会有一股神秘感。 提交于 2019-12-05 18:29:42
The problem is, that I have a QVector of QSharedPointer and I want to put part of them to my QCache . How can I insert a shared pointer to QCache ? What happens if I set the pointer to my cache but destroy the QVector and the shared pointer in it? Will the memory be released and my cache points to nowhere? It is a bug if you put just a pointer to your item to QChache and at the same time such pointer is managed by QSharedPointer . The item object can be destroyed by QSharedPointer destructor, so QChache will have invalid pointer. It is a generic issue that you cannot have different owners of a

Attaching signals and slots to an object within a QSharedPointer

坚强是说给别人听的谎言 提交于 2019-12-03 13:02:42
My application contained several functions like this: void SomeClass::set_data_provider(DataProvider *data_provider) { connect(data_provider, SIGNAL(data_available(int)), this, SLOT(data_available(int))); } To avoid passing raw pointers around I have changed all occurrences of DataProvider * to QSharedPointer<DataProvider> . The latter is almost a drop-in replacement for the former, except that you can’t pass a QSharedPointer to QObject::connect . I worked around this by extracting a raw pointer from the QSharedPointer: void SomeClass::set_data_provider(QSharedPointer<DataProvider> data