1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #include "classe.h"
classe::classe() {
setupUi(this);
QObject::connect(&req, SIGNAL(done(bool)), this, SLOT(affiche(bool)));
QObject::connect(&req, SIGNAL(dataSendProgress(int, int)), this, SLOT(majPB(int, int)));
QObject::connect(&req, SIGNAL(requestFinished(int, bool)), this, SLOT(fin(int, bool)));
QObject::connect(m_button, SIGNAL(pressed()), this, SLOT(execReq()));
QObject::connect(&req, SIGNAL(dataReadProgress(int, int)), this, SLOT(majPB(int, int)));
show();
}
void classe::majPB(int _done, int _total){
m_progressBar->setMaximum(_total);
m_progressBar->setValue(_done);
}
void classe::fin(int _id, bool _error) {
if(_error)
QMessageBox::information(0, "Fin", QString().setNum(req.error()));
}
void classe::affiche(bool) {
m_textEdit->setText(QString(req.readAll().data()));
}
void classe::execReq() {
QStringList tmp = m_adresse->text().split("/");
QString host;
QString page = "/";
if(tmp[0] != "http:"){
host = tmp[0];
for(int i=1;i<tmp.count();i++)
page+="/"+tmp[i];
} else {
host = tmp[2];
for(int i=3;i<tmp.count();i++)
page+="/"+tmp[i];
}
req.setHost(host);
QHttpRequestHeader header("POST",page);
header.setValue("Host",host);
header.setValue("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14");
req.request(header);
} |