Repository navigation
Expand file tree
/
Copy pathdownloader.cpp
More file actions
56 lines (41 loc) · 1.67 KB
/
Copy pathdownloader.cpp
File metadata and controls
56 lines (41 loc) · 1.67 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "downloader.h"
Downloader::Downloader(QObject *parent) : QObject(parent)
{
// Trying to measure progress using a QNetworkReply object ended up being too much
// work, and according to some, not very useful when the file size isn't returned.
// http://www.bogotobogo.com/Qt/Qt5_QNetworkRequest_Http_File_Download.php
// Connect progress and finished to our slot
connect(&manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
}
Downloader::~Downloader() { }
void Downloader::startDownload(QString url)
{
// Start the download
manager.get(QNetworkRequest(QUrl(url)));
}
void Downloader::downloadFinished(QNetworkReply* reply)
{
// Save the file as a QByteArray
qbaDownloadedData = reply->readAll();
if(reply->error())
{
//qDebug() << "File download error: " << reply->errorString();
// emit a signal
emit downloadFailed();
}
else
{
//qDebug() << "Content type: " << reply->header(QNetworkRequest::ContentTypeHeader).toString();
//qDebug() << "Last modified: " << reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toString();
//qDebug() << "File size: " << reply->header(QNetworkRequest::ContentLengthHeader).toULongLong();
//qDebug() << "HTTP Status Code Attribute: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
//qDebug() << "HTTP Reason Phrase: " << reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
//emit a signal
emit downloadSuccess();
}
reply->deleteLater();
}
QByteArray Downloader::downloadedData() const
{
return qbaDownloadedData;
}