First of all I'm trying perform synchronous HTTP requests. QNetworkAccessManager doesn't seem to offer support for it, so I'm trying to emulate this with a separate event loop.
QNetworkAccessManager NAManager;
QUrl url
("http://www.google.com");
QNetworkRequest request(url);
QNetworkReply *reply = NAManager.get(request);
QObject::connect(reply,
SIGNAL(finished
()),
&eventLoop,
SLOT(quit
()));
eventLoop.exec();
std::cout << "finished" << std::endl; //request finished here
QNetworkAccessManager NAManager;
QUrl url ("http://www.google.com");
QNetworkRequest request(url);
QNetworkReply *reply = NAManager.get(request);
QEventLoop eventLoop;
QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
eventLoop.exec();
std::cout << "finished" << std::endl; //request finished here
To copy to clipboard, switch view to plain text mode
Question: is there a nicer way to achieve this?
Another question: is it possible to create an event loop that allows you to manually post events to it?
Bookmarks