1.pro文件添加
QT += core gui network
2.头文件
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QFile>
3.widget.h文件
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QFile>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = nullptr);
~Widget();
QNetworkAccessManager *manager;
QNetworkReply *reply;
QFile *myfile;
void Init();
void doProcessReadyRead();
void doProcessFinished();
void doProcessDownloadProgress(qint64,qint64);
void doProcessError(QNetworkReply::NetworkError code);
private slots:
void on_pushButton_clicked();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H