Thanks Wysota!!
For a very long time I've been spinning my wheels without having any idea what's going on. Now it seems that asynchronous is the keyword for me. However, I have to admit I don't know how to use this knowledge. I've been leraning from here http://doc.trolltech.com/4.4/qnetworkaccessmanager.html
and I get things to work for one request but all falls apart when I have a while loop and try to do multiple queries. Would someone be able to do me a huge favor and perhaps show how this code could be changed to accept multiple requests.
Here's my code:
for(int y=1; y<10; y++)
{
QNetworkAccessManager* nam = new QNetworkAccessManager(this);
QNetworkReply* reply;
fscanf(namefeed, "%s", &sona);
urlstring
=QString::fromLocal8Bit(sona,
strlen(sona
)); url.
setUrl(urlstring
);
QObject::connect(nam,
SIGNAL(finished
(QNetworkReply
*)),
this,
SLOT(replyFinished
(QNetworkReply
*)));
reply = nam->get(QNetworkRequest(url)); url.clear();
}
for(int y=1; y<10; y++)
{
QNetworkAccessManager* nam = new QNetworkAccessManager(this);
QNetworkReply* reply;
fscanf(namefeed, "%s", &sona);
urlstring=QString::fromLocal8Bit(sona, strlen(sona)); url.setUrl(urlstring);
QObject::connect(nam, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
reply = nam->get(QNetworkRequest(url)); url.clear();
}
To copy to clipboard, switch view to plain text mode
void MyClass::replyFinished(QNetworkReply* reply)
{
QVariant statusCodeV
= reply
->attribute
(QNetworkRequest
::HttpStatusCodeAttribute);
if (statusCodeV.toInt()==200){
//do something
}
else{
// do something else
}
delete reply;
}
void MyClass::replyFinished(QNetworkReply* reply)
{
QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
if (statusCodeV.toInt()==200){
//do something
}
else{
// do something else
}
delete reply;
}
To copy to clipboard, switch view to plain text mode
Bookmarks