-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiledownloader.cpp
More file actions
27 lines (23 loc) · 821 Bytes
/
filedownloader.cpp
File metadata and controls
27 lines (23 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "filedownloader.h"
FileDownloader::FileDownloader(QUrl url, QObject *parent) :
QObject(parent)
{
QNetworkRequest request(url);
file.setFileName(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)+"/"+url.fileName());
file.open(QIODevice::ReadWrite);
m_reply = m_WebCtrl.get(request);
connect(m_reply, SIGNAL (readyRead()), this, SLOT (newData()));
connect(m_reply, SIGNAL (downloadProgress(qint64, qint64)), this, SIGNAL(progressChanged(qint64,qint64)));
connect(m_reply, SIGNAL (finished()), this, SLOT (noMoreData()));
}
FileDownloader::~FileDownloader() {
file.remove();
}
void FileDownloader::newData(){
file.write(m_reply->readAll());
}
void FileDownloader::noMoreData(){
file.close();
m_reply->deleteLater();
emit downloaded(&file);
}