myWallJSON
myWallJSON

Reputation: 9502

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

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?

Upvotes: 4

Views: 4483

Answers (2)

Emanuele Bezzi
Emanuele Bezzi

Reputation: 1728

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

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

Upvotes: 7

Mat
Mat

Reputation: 206689

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.

Upvotes: 4

Related Questions