If you do not see the content of the file, something went wrong. Just as in real life, this can often happen. So, we need to ensure that there is a good error handling mechanism in such cases to inform the user about what is going on. Fortunately, QNetworkReply offers several possibilities to do this.
In the slot called downloadFinished(), we first want to check whether an error occurred:
if (reply->error() != QNetworkReply::NoError) { // error occurred }
The QNetworkReply::error() function returns the error that occurred while handling the request. The error is encoded as a value of the QNetworkReply::NetworkError type. The most common errors are probably these:
Error code | Meaning |