Simplest way to download from the HTTP is below::
connect(&http,SIGNAL(done(bool)),this,SLOT(httpdone())); //added in the constructor..
connect(&http,SIGNAL(done(bool)),this,SLOT(httpdone())); //added in the constructor..
To copy to clipboard, switch view to plain text mode
In the header file......Make the following changes...
private slots:
bool on_pushButton_clicked();
void httpdone();
signals:
void done();
in the Qthttp.cpp file...
bool QtHttp::on_pushButton_clicked()
{
QString strUrl
="http://www.blabla.com//file";
QString filename
=fileInfo.
fileName();
file.setFileName("C:\\Qt\\QHttp\\"+filename);
http.setHost(url.host(),url.port(80));
http.get(url.path(),&file);
{
}
file.write(http.readAll());
http.close();
return true;
}
void QtHttp::httpdone()
{
file.close();
Q_EMIT done();
}
QHttp http;
QFile file;
private slots:
bool on_pushButton_clicked();
void httpdone();
signals:
void done();
in the Qthttp.cpp file...
bool QtHttp::on_pushButton_clicked()
{
QString strUrl="http://www.blabla.com//file";
QUrl url = QUrl::fromUserInput(strUrl);
QFileInfo fileInfo(url.path());
QString strhost=url.encodedHost();
QString filename=fileInfo.fileName();
file.setFileName("C:\\Qt\\QHttp\\"+filename);
http.setHost(url.host(),url.port(80));
http.get(url.path(),&file);
if(!file.open(QIODevice::WriteOnly))
{
QMessageBox::warning(NULL,"warning","file is not opened",QMessageBox::Ok);
}
file.write(http.readAll());
http.close();
return true;
}
void QtHttp::httpdone()
{
file.close();
Q_EMIT done();
}
To copy to clipboard, switch view to plain text mode
Bookmarks