#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileInfo>
#include <QMessageBox>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
url.setUrl("http://google.ge/");
ui->lineEdit->setText(url.toString());
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(downloadButton()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::downloadButton()
{
url.setUrl(ui->lineEdit->text());
request.setUrl(url);
QString fileName
= fileInfo.
fileName();
if(fileName.isEmpty())
fileName = "index.html";
file = new QFile(fileName
);
startRequest();
}
void MainWindow::startRequest()
{
reply = nmanager.get(request);
connect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));
connect(reply,SIGNAL(readyRead()),this,SLOT(httpReady()));
//QMessageBox::information(this,"ads","asd");
}
void MainWindow::httpFinished()
{
reply->deleteLater();
reply = 0;
file->close();
file = 0;
}
void MainWindow::httpReady()
{
file->write(reply->readAll());
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileInfo>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
url.setUrl("http://google.ge/");
ui->lineEdit->setText(url.toString());
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(downloadButton()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::downloadButton()
{
url.setUrl(ui->lineEdit->text());
request.setUrl(url);
QFileInfo fileInfo = url.path();
QString fileName = fileInfo.fileName();
if(fileName.isEmpty())
fileName = "index.html";
file = new QFile(fileName);
file->open(QIODevice::WriteOnly);
startRequest();
}
void MainWindow::startRequest()
{
reply = nmanager.get(request);
connect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));
connect(reply,SIGNAL(readyRead()),this,SLOT(httpReady()));
//QMessageBox::information(this,"ads","asd");
}
void MainWindow::httpFinished()
{
reply->deleteLater();
reply = 0;
file->close();
file = 0;
}
void MainWindow::httpReady()
{
file->write(reply->readAll());
}
To copy to clipboard, switch view to plain text mode
Bookmarks