Deleting pointers in slot
-
This is a member function which I use for uploading files using HTTP
void HTTP::UploadFile(QNetworkRequest request, QFileInfo filePath){ QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); multiPart_list.append(multiPart); // Store in a list . . . UploadManager.post(request, multiPart); }When uploading is complete, below slot is called by QNetworkAccessManager::finished signal
void HTTP::UploadingFinished(QNetworkReply *reply){ qDebug() << "Uploading Finished!"; reply->deleteLater(); }I want to delete multiPart* in HTTP::UploadingFinished() slot (to avoid memory leak).
Everytime HTTP::UploadFile(..) is called, A new multiPart is allocated and appended to the below QListQList<QHttpMultiPart*> multiPart_list; // Class AttributeI need a mechanism clean these pointer in UploadingFinished(..) slot.
-
This is a member function which I use for uploading files using HTTP
void HTTP::UploadFile(QNetworkRequest request, QFileInfo filePath){ QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); multiPart_list.append(multiPart); // Store in a list . . . UploadManager.post(request, multiPart); }When uploading is complete, below slot is called by QNetworkAccessManager::finished signal
void HTTP::UploadingFinished(QNetworkReply *reply){ qDebug() << "Uploading Finished!"; reply->deleteLater(); }I want to delete multiPart* in HTTP::UploadingFinished() slot (to avoid memory leak).
Everytime HTTP::UploadFile(..) is called, A new multiPart is allocated and appended to the below QListQList<QHttpMultiPart*> multiPart_list; // Class AttributeI need a mechanism clean these pointer in UploadingFinished(..) slot.
@pingal If you take a look at https://doc.qt.io/qt-5/qhttpmultipart.html you will see:
multiPart->setParent(reply); // delete the multiPart with the replyWhy not doing it this way instead of implementing complex logic with lists?
-
@pingal said in Deleting pointers in slot:
Actually i'm not used to QObject->setParent(..)
Take a look at https://doc.qt.io/qt-5/objecttrees.html - this is an important concept in Qt.