Qt, should we delete the QNetworkReply * response received in the SIGNAL QNetworkAccessManager?

Let's say that we have:

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

and

 void finished(QNetworkReply* reply);

If we delete the answer inside finished, we get segfault. Does this mean that we will not free him?

+3
source share
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 ().

+5
source

From the QNetworkAccessManagerdocs for the signal finished:

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

Indeed, you should not delete it, but call deleteLater.

+3
source

All Articles