O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required