#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
manager = new QNetworkAccessManager(this);
ui->progressBar->hide();
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_clicked()
{
url =ui->lineEdit->text();
QFileInfo info(url.path());
QString fileName(info.fileName());
if(fileName.isEmpty())
fileName = "index.html";
file = new QFile(fileName);
if(!file->open(QIODevice::WriteOnly))
{
qDebug()<<"file open error";
delete file;
file = 0;
return ;
}
startRequest(url);
ui->progressBar->setValue(0);
ui->progressBar->show();
}
void Widget::startRequest(QUrl url)
{
reply = manager->get(QNetworkRequest(url));
connect(reply,SIGNAL(finished()),
this,SLOT(httpfinished()));
connect(reply,SIGNAL(readyRead()),
this,SLOT(httpReadyRead()));
connect(reply,SIGNAL(downloadProgress(qint64,qint64)),
this, SLOT(updateDateReadProgress(qint64,qint64)));
}
void Widget::httpReadyRead()
{
if(file)
file->write(reply->readAll());
}
void Widget::updateDateReadProgress(qint64 bytesRead,qint64 totalBytes)
{
ui->progressBar->setMaximum(totalBytes);
ui->progressBar->setValue(bytesRead);
}
void Widget::httpfinished()
{
ui->progressBar->hide();
file->flush();
file->close();
reply->deleteLater();
reply = 0;
delete file;
file = 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
http1.rar_qt 网络_qt浏览器
共6个文件
cpp:2个
pro:1个
user:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 59 浏览量
2022-09-24
17:25:05
上传
评论
收藏 3KB RAR 举报
温馨提示
是一个浏览器的源代码,能通过网络地址得到相关的信息
资源推荐
资源详情
资源评论
收起资源包目录
http1.rar (6个子文件)
http1
widget.h 637B
widget.ui 1KB
http1.pro 334B
main.cpp 181B
http1.pro.user 8KB
widget.cpp 2KB
共 6 条
- 1
资源评论
寒泊
- 粉丝: 74
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功