Time for action – Displaying a proper error message

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

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.