QNetworkAccessManager, QNetworkRequest, and QNetworkReply are all very easy to use in my opinion and that's what I'd recommend that you use for this task.
True that the nature of the Qt networking classes above is asynchronous and you can force a synchronous nature by using a QEventLoop, but that generally prompts the question "Why isn't using signals/slots acceptable?"
Threading is much more complex if done correctly. Most people that wind up implementing threading in Qt cobble something together that works most of the time, but isn't actually implemented correctly. If you insist on trying to force a synchronous behaviour, then the snippet below should get you started:
QNetworkAccessManager nam;
QRequest req
(QUrl("http://google.com"));
QNetworkReply *reply = nam.get(req);
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
QEventLoop loop;
QNetworkAccessManager nam;
QRequest req(QUrl("http://google.com"));
QNetworkReply *reply = nam.get(req);
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
QByteArray buffer = reply->readAll();
To copy to clipboard, switch view to plain text mode
Bookmarks