Higgs
16th April 2014, 10:20
Hi all.
I have writen code which downloads simple file. html file.
code is here:
#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(downloadBut ton()));
}
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(httpFin ished()));
connect(reply,SIGNAL(readyRead()),this,SLOT(httpRe ady()));
//QMessageBox::information(this,"ads","asd");
}
void MainWindow::httpFinished()
{
reply->deleteLater();
reply = 0;
file->close();
file = 0;
}
void MainWindow::httpReady()
{
file->write(reply->readAll());
}
I request page,that requires login autorization, username: and password:
I want my code to type automatically this fields(username and password) and then download page,which is after login autorization.
How can I do it?
p.s sorry fo my bad English.
I have writen code which downloads simple file. html file.
code is here:
#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(downloadBut ton()));
}
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(httpFin ished()));
connect(reply,SIGNAL(readyRead()),this,SLOT(httpRe ady()));
//QMessageBox::information(this,"ads","asd");
}
void MainWindow::httpFinished()
{
reply->deleteLater();
reply = 0;
file->close();
file = 0;
}
void MainWindow::httpReady()
{
file->write(reply->readAll());
}
I request page,that requires login autorization, username: and password:
I want my code to type automatically this fields(username and password) and then download page,which is after login autorization.
How can I do it?
p.s sorry fo my bad English.