Time for action – showing the download progress

In order to achieve this, we can use the reply's downloadProgress() signal. As the first argument, it passes the information on how many bytes have already been received and as the second argument, how many bytes there are in total. This gives us the possibility to indicate the progress of the download with QProgressBar. As the passed arguments are of the qint64 type, we can't use them directly with QProgressBar, as it only accepts int. So, in the connected slot, we first calculate the percentage of the download progress:

void SomeClass::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { qreal progress = (bytesTotal < 1) ? 1.0 : bytesReceived * 100.0 / bytesTotal; progressBar->setValue(progress ...

Get Game Programming Using Qt 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.