Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt shall we delete QNetworkReply* reply received on QNetworkAccessManager SIGNAL?

Tags:

c++

qt

Say we have:

pManager  = new QNetworkAccessManager();
QObject::connect(pManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(finishedSlot(QNetworkReply*)));

and

 void finished(QNetworkReply* reply);

If we delete reply inside finished we will get segfault. Does this mean we shall not free it?

like image 413
myWallJSON Avatar asked Dec 21 '22 22:12

myWallJSON


2 Answers

From http://doc.qt.io/qt-5/qnetworkreply.html:

Note: Do not delete the object in the slot connected to this signal. Use deleteLater().

like image 197
Emanuele Bezzi Avatar answered Dec 23 '22 13:12

Emanuele Bezzi


From the QNetworkAccessManager docs for the finished signal:

Note: Do not delete the reply object in the slot connected to this signal. Use deleteLater().

So indeed, you should not delete it, but call deleteLater.

like image 29
Mat Avatar answered Dec 23 '22 13:12

Mat