I'm a novice regarding both C++ and Qt. This class is used in my project to get an image from a web service.

If a new call to StartDownload is made before the previous has finished, the old one can safely be discarded as it won't be needed any more. This is because a new request is made for each resize event, as one of the parameters to the service is the image size (font size in the image is adapted to the image size).

As a result, when a request is canceled, Qt prints an error message: QCoreApplication::postEvent: Unexpected null receiver. This does not interfere with any functionality, but tells me I haven't handled canceling the request properly. Several of these messages are printed as I resize the window and CancelDownload is called.

Aside from that, any general feedback on my design or C++ idiomacy is welcome!

Note: I'm using C++11 and Qt 5.6.

#ifndef DOWNLOADER_H

#include <QtNetwork/qnetworkaccessmanager.h>
#include <qbytearray.h>
#include <QObject>

{
Q_OBJECT

public:

private:

QNetworkAccessManager mNetworkAccessManager;

signals:

private slots:
};



### Source

#include <QtNetwork/qnetworkrequest.h>

{
}

{
mNetworkAccessManager.deleteLater();
}

{
}
}

{

QNetworkRequest request(url);
}

{
return;
}

}
}

}


### Update

Although I solved the issue described above in a self-answer, I am still looking for a general review!

The error message is caused by me misunderstanding the purpose of deleteLater. As implied by the documentation, the member function is only required when deleting the object inside a slot, like HandleFinishedDownload.

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

In all other cases, the standard delete keyword should be used. As a result, here is an updated implementation of CancelDownload.

void Downloader::CancelDownload()
{
delete mCurrentReply; // this is the only altered line