利用qt和国产库libhv实现通过url下载文件

头文件

#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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值