Here is the code of the app.:
void polje::skoci() {
int i = 0;
bool bOk;
int st = str.toInt(&bOk) + 1;
//write new number into textfield t_1
ui.
t_1->setText
(QString::number(st
));
//define http path = in this example i'm using static URL, in the real case
//it is collected from database
//the URL below is the one making problems... <=host not found since it does not exist, but the loop end and I can not start it
QUrl urlt
("http://www.anabanana.brb/");
//the URL below has corect host address, but the file is missing - responseHeader code 404
// QUrl urlt("http://www.bubi.si/luka.html");
//the URL below is correct, just to test if the app. work
// QUrl urlt("http://www.google.com/");
//define the path to the file into which we will write the contend of the page
QDir pot
(qApp
->applicationDirPath
());
if(!pot.exists("html")) {
pot.mkdir("html");
}
file = new QFile("html/blog_" + QString::number(st
) + ".html");
QMessageBox::critical(this,
"Napaka",
"Ne morem odpreti datoteke.");
delete file;
return;
}
//open the connection and download the content of the page
//into the file specified
http->setHost(urlt.host());
httpGetId = http->get(urlt.path(), file);
}
void polje::httpRequestFinished(int requestId, bool error) {
if (requestId != httpGetId)
return;
//we close the specific file
file->close();
if (error) {
//insert the error string into textfield t_2
//just to find out what the error is
ui.t_2->insertPlainText("\n" + ui.t_1->text() + ": " + http->errorString());
}
else {
bool bOk;
int st = str.toInt(&bOk) + 1;
if (st <= 10) {
skoci();
}
}
}
ui.
t_2->insertPlainText
("\n" + ui.
t_1->text
() + ": " + QString::number(responseHeader.
statusCode()));
}
void polje::skoci() {
int i = 0;
bool bOk;
QString str = ui.t_1->text();
int st = str.toInt(&bOk) + 1;
//write new number into textfield t_1
ui.t_1->setText(QString::number(st));
//define http path = in this example i'm using static URL, in the real case
//it is collected from database
//the URL below is the one making problems... <=host not found since it does not exist, but the loop end and I can not start it
QUrl urlt("http://www.anabanana.brb/");
//the URL below has corect host address, but the file is missing - responseHeader code 404
// QUrl urlt("http://www.bubi.si/luka.html");
//the URL below is correct, just to test if the app. work
// QUrl urlt("http://www.google.com/");
//define the path to the file into which we will write the contend of the page
QDir pot(qApp->applicationDirPath());
if(!pot.exists("html")) {
pot.mkdir("html");
}
file = new QFile("html/blog_" + QString::number(st) + ".html");
if (!file->open(QIODevice::WriteOnly)) {
QMessageBox::critical(this, "Napaka", "Ne morem odpreti datoteke.");
delete file;
return;
}
//open the connection and download the content of the page
//into the file specified
http->setHost(urlt.host());
httpGetId = http->get(urlt.path(), file);
}
void polje::httpRequestFinished(int requestId, bool error) {
if (requestId != httpGetId)
return;
//we close the specific file
file->close();
if (error) {
//insert the error string into textfield t_2
//just to find out what the error is
ui.t_2->insertPlainText("\n" + ui.t_1->text() + ": " + http->errorString());
}
else {
bool bOk;
QString str = ui.t_1->text();
int st = str.toInt(&bOk) + 1;
if (st <= 10) {
skoci();
}
}
}
void polje::readResponseHeader(const QHttpResponseHeader &responseHeader) {
ui.t_2->insertPlainText("\n" + ui.t_1->text() + ": " + QString::number(responseHeader.statusCode()));
}
To copy to clipboard, switch view to plain text mode
I have defined QHttp and the rest of undefined variables in the header file in the private section:
int httpGetId;
QHttp *http;
QFile *file;
int httpGetId;
To copy to clipboard, switch view to plain text mode
Can anybody find the explanation and perhaps even the solution? Thank you!
Regards;
Luka
Bookmarks