qDebug() << _url.path(); QNetworkRequest request(_url); _manager.get(request); connect(&_manager, SIGNAL(finished(QNetworkReply*)) , this, SIGNAL(finished(QNetworkReply*)));
#ifndef RFILEDOWNLOADER_H#define RFILEDOWNLOADER_H//--------Qt Headers#include <QObject>#include <QString>#include <QNetworkAccessManager>#include <QNetworkReply>#include <QUrl>//-------My and other headers//-------class RFileDownloader: public QObject{ Q_OBJECTpublic: explicit RFileDownloader(QObject *parent = 0); explicit RFileDownloader(const QString &url = QString(), QObject *parent = 0); explicit RFileDownloader(const QUrl &url = QUrl(), QObject *parent = 0); ~RFileDownloader(); //Url void setUrl(const QString &url) {_url = QUrl(url);} void setUrl(const QUrl &url) {_url = url;} QUrl url() const {return _url;}private: QNetworkAccessManager _manager; QUrl _url;public slots: void startDownloading(QUrl url = QUrl()); void startDownloading(const QString &url);signals: void finished(QNetworkReply *reply);};#endif // RFILEDOWNLOADER_H
//--------Qt Headers#include <QNetworkRequest>#include <QDebug>//-------My and other headers#include <Classes/RFileDownloader/RFileDownloader.h>//-------RFileDownloader::RFileDownloader(QObject *parent) : QObject(parent){}RFileDownloader::RFileDownloader(const QString &url, QObject *parent) : QObject(parent){ _url.setPath(url);}RFileDownloader::RFileDownloader(const QUrl &url, QObject *parent) : QObject(parent){ _url = url;}RFileDownloader::~RFileDownloader(){}void RFileDownloader::startDownloading(QUrl url){ //If url is empty use _url if (!url.isEmpty()) _url = url; qDebug() << _url.path(); QNetworkRequest request(_url); _manager.get(request); connect(&_manager, SIGNAL(finished(QNetworkReply*)) , this, SIGNAL(finished(QNetworkReply*)));}void RFileDownloader::startDownloading(const QString &url){ QUrl urlForDownload; urlForDownload.setPath(url); startDownloading(urlForDownload);}
//Download icon from site _iconDownloader = new RFileDownloader("http://ru.wikipedia.org/favicon.ico", this); connect(_iconDownloader, SIGNAL(finished(QNetworkReply*)), this, SLOT(iconWasDownload(QNetworkReply*))); _iconDownloader->startDownloading();
C++ (Qt)class RFileDownloader: public QObject{public: QNetworkAccessManager *netManager() { return &_manager; }}..._iconDownloader = new RFileDownloader("http://ru.wikipedia.org/favicon.ico", this);connect(_iconDownloader->netManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(iconWasDownload(QNetworkReply*)));_iconDownloader->startDownloading();
RFileDowloader down = "asdf.com"
RFileDowloader down("asdf.com")