/* * FileDownloader.cpp * * Created on: Mar 7, 2014 * Author: nils */ #include #include "FileDownloader.h" FileDownloader::FileDownloader(QObject *parent) : QObject(parent) { connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)), SLOT(fileDownloaded(QNetworkReply*))); } FileDownloader::~FileDownloader() { } void FileDownloader::connectSlot(QObject* obj, const char* slot) { QObject::connect(this, SIGNAL(downloaded(QString&, QByteArray)), obj, slot); } void FileDownloader::fileDownloaded(QNetworkReply* pReply) { QByteArray downloadedData = pReply->readAll(); //emit a signal pReply->deleteLater(); emit downloaded(this->fileName, downloadedData); this->deleteLater(); // TODO: RAII - Object should not delete itself } void FileDownloader::downloadFile(const QUrl& fileUrl) { this->fileName = fileUrl.toString(); m_WebCtrl.get(QNetworkRequest(fileUrl)); }