Time for action – Downloading a file

Create a Qt Widgets project and add a widget class named FileDownload. Add a button that will start the download and a plain text edit that will display the result. As always, you can look at the code files provided with the book if you need any help.

Next, enable the Qt Network module by adding QT += network to the project file. Then, create an instance of QNetworkAccessManager in the constructor and put it in a private field:

m_network_manager = new QNetworkAccessManager(this); 

Since QNetworkAccessManager inherits QObject, it takes a pointer to QObject, which is used as a parent. Thus, you do not have delete the manager later on.

Secondly, we connect the manager's finished() signal to a slot of our ...

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.