Hi all,

I am using QNetworkAccessManager in order to download a file from the Internet in the following way:

Qt Code:
  1. void MainWindow::readUrlResource(const QString &url) {
  2. QNetworkRequest request;
  3. request.setUrl(QUrl(url));
  4.  
  5. QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
  6.  
  7. //Get notified when the download completes
  8. connect(networkManager, SIGNAL(finished(QNetworkReply*)),
  9. this, SLOT(urlResourceDownloadCompleted(QNetworkReply*)));
  10.  
  11. networkManager->get(request);
  12. }
To copy to clipboard, switch view to plain text mode 

The function above is part of my main window (inheriting from QMainWindow) and it is what is sent as "this" to QNetworkAccessManager constructor. Also, the urlResourceDownloadCompleted() slot looks like this:

Qt Code:
  1. void MainWindow::urlResourceDownloadCompleted(QNetworkReply *reply) {
  2. //TODO: Handle the case when an error occurs during download
  3.  
  4. qDebug() << "Download completed signal received";
  5.  
  6. reply->deleteLater();
  7. }
To copy to clipboard, switch view to plain text mode 

I am wondering whether I need to explicitly delete networkManager in some way or will QMainWindow (parent to it) take care of this eventually? I will have QMainWindow visible for a long time on screen so if it is it taking care of deletion, I wouldn't want to wait for so long, as I might want to create more networkManagers during this time.

If I need to delete the networkManager pointer manually, which is the best place to do so?

I am just trying my best to avoid potential memory leak due to not deleting networkManager pointer.

Thank you in advance. I am very new to Qt and I have some minor experience in C++ but I am having much fun so far and would like to learn thing properly.

Kind Regards,
Veroslav