Utilizing QNetworkAccessManager
Now, we're going to discover how to write an application that is able to download files from other locations. By other locations, we mean that you can download files from a local position; it doesn't have to be an Internet address, since the local file URLs are supported by Qt as well.
First of all, let's create a Downloader
class that will use QNetworkAccessManager
to do the downloading work for us. The downloader.h
header file is pasted shown as follows:
#ifndef DOWNLOADER_H #define DOWNLOADER_H #include <QObject> #include <QNetworkAccessManager> #include <QNetworkRequest> #include <QNetworkReply> class Downloader : public QObject { Q_OBJECT public: explicit Downloader(QObject *parent = 0); public slots: void download(const QUrl &url, const QString &file); signals: void errorString(const QString &); void available(bool); void running(bool); void downloadProgress(qint64, qint64); private: QNetworkAccessManager...