List of HTTP Requests
-
Hi everyone, I will explain my problem
I have a simple class to manage the picture downloads and looks like:
@
void NetworkHandler::getImage(QString name, const QObject *amember, const char * atype, const char * atype2){
QNetworkAccessManager * http = new QNetworkAccessManager();
reply = http->get(QNetworkRequest(QUrl(name)));
connect(reply, SIGNAL(finished()), amember, atype);
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), amember, atype2);
}QByteArray NetworkHandler::readData() {
return reply->readAll();
}@
It works perfectly for one picture, but the problem comes when I want to download more than one, it crashes because I'm using the QNetworkReply object for the first one. I could build another class but I want to do it generic.
I tried including another QNetworkReply object for each call but it doesn't work, I don't know why.
Does anyone knows what can I do?
Thanks in advance.
-
Use sender() in your slot?
(And watch out: you're leaking memory for your QNAM objects, and that's a bad use case -- build only one QNAM for your application and use it for all your requests).
-
Hi, sorry for the late response.
I solved the problem you told me and I built just one QNAM to manage the requests. I have a special class managing the network requests with a post method and a readData method as I wrote in the last message.
It uses just one QNetworkReply to get the answer of the request. What will happend when I make two asynchronous requests in a row and the second one is thrown before the first one comes back?
Do I have to create a list of QNetworkReplys to manage it?
Thank you a lot!