Answer the question
In order to leave comments, you need to log in
How to handle multiple get requests in QNetworkAccessManager?
I have a certain number of links (more than 6) for which I want to get the html code of these pages.
And I have to glue them in the process of obtaining. The only question is, how do I send these requests and how do I process them in the slot so that I can end up with a page that is in the same order as the links?
I am trying to do the following:
void MyLoader::loadPageByLinks()
{
// links - это QStringList
for(const QString& link : links)
{
manager->get(QNetworkRequest(QUrl(link)));
}
}
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyReady(QNetworkReply*)));
void MyLoader::replyReady(QNetworkReply *reply)
{
QString currentPage(reply->readAll());
... // делаю преобразования currentPage с помощью регулярных выражений
finalPage.append(currentPage); // добавляю к финальной странице текущую (псевдокод)
}
Answer the question
In order to leave comments, you need to log in
get( and post( return a reference to the QNetworkReply that comes in the response.
You can use setProperty to set your own values.
This way you can identify which request the response came from.
The order of responses for multiple requests may be different, since QNetworkAccessManager uses 4 connections at the same time .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question