头文件
#ifndef __LIB_DOWNLOAD_H__
#define __LIB_DOWNLOAD_H__
#include <memory>
#include <QObject>
#include <QUrl>
#include <QFile>
#include <QDir>
#include <QPointer>
#include <QApplication>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include <QStandardPaths>
class DownLoadFileHttps : public QObject
{
Q_OBJECT
public:
// 参数1=下载链接 参数2=保存的路径 参数3=父窗口地址
explicit DownLoadFileHttps(const QString& downloadUrl,
const QString& fileName,
QObject* parent = nullptr);
//析构,不解释
~DownLoadFileHttps();
bool startDownload(); // 开始下载文件
void cancelDownload(); // 取消下载文件
Q_SIGNALS:
// 下载进度信号
void sigProgress(qint64 bytesRead, qint64 totalBytes, qreal progress);
// 下载完成信号
void sigDownloadFinished();
private Q_SLOTS:
// QNetworkReply::finished对应的槽函数
void httpFinished();
// QIODevice::readyRead对应的槽函数
void httpReadyRead();
// QNetworkReply::downloadProgress对应的槽函数
void networkReplyProgress(qint64 bytesRead, qint64 totalBytes);
private:
void startRequest(const QUrl& requestedUrl);
std::unique_ptr<QFile> openFileForWrite(c