———————下载器制作———————
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qfiledialog.h"
#include "qstring.h"
#include "qdebug.h"
#include "qnetworkaccessmanager.h"
#include "QNetworkReply"
#include "QNetworkRequest"
QNetworkAccessManager * manager;
QNetworkReply *reply;
QFile *file;
QNetworkRequest request;
//绑定可读数据槽,接收到数据,就会触发
connect(reply, &QIODevice::readyRead, this, &MainWindow::slotReadyRead);
//绑定下载进度
connect(reply, &QNetworkReply::downloadProgress, this, &MainWindow::downloadRepose);
reply = manager->get(request);
void MainWindow::downloadRepose(qint64 bytesReceived, qint64 bytesTotal)
{
ui->progressBar->setRange(0,bytesTotal);
ui->progressBar->setValue(bytesReceived);
qDebug() << bytesTotal <<":" << bytesReceived;
if( bytesTotal == bytesReceived )
file->close();
qDebug() << "下载完成";
}
🎈 -1- 按键按下创建文件,打开文件
🎈 -2- 发送请求获取数据
🎈 -3- 接收数据写入文件
🎈 -4- 文件下载完毕关闭文件
🎈 -5- 此时可以在设置路径查看文件
———————代码获取查看下方———————