-
Notifications
You must be signed in to change notification settings - Fork 0
/
sha1sum.cpp
37 lines (28 loc) · 860 Bytes
/
sha1sum.cpp
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
#include "sha1sum.h"
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QCryptographicHash>
#include <memory>
namespace util {
Sha1Sum::Sha1Sum(QObject* parent) : QObject(parent)
{}
void Sha1Sum::start(const QString& requestUrl)
{
QNetworkReply* reply(networkAccessManager_.get(QNetworkRequest(requestUrl)));
std::shared_ptr<QCryptographicHash> sha1hash = std::make_shared<QCryptographicHash>(QCryptographicHash::Sha1);
connect(reply, &QNetworkReply::downloadProgress, this, &Sha1Sum::progress);
connect(reply, &QIODevice::readyRead, this, [=] () {
sha1hash->addData(reply);
});
connect(reply, &QNetworkReply::finished, this, [=] () {
result_ = sha1hash->result().toHex();
emit finished();
reply->deleteLater();
});
emit started();
}
QString Sha1Sum::result() const
{
return result_;
}
} // namespace util