QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); QNetworkRequest request(QUrl("http://example.com")); QNetworkReply* reply = networkManager->get(request); connect(reply, &QNetworkReply::finished, [reply]() { QByteArray data = reply->readAll(); qDebug() << data; });
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); QNetworkRequest request(QUrl("http://nonexistentdomain.com")); QNetworkReply* reply = networkManager->get(request); connect(reply, &QNetworkReply::errorOccurred, [reply]() { qDebug() << "Error: " << reply->errorString(); });In this example, we attempt to send a GET request to a nonexistent domain. When this request fails, the QNetworkReply::errorOccurred signal is emitted. We connect to this signal and output a message to the console indicating that an error occurred, along with the error message provided by `errorString()`. Package library: QtNetwork Overall, QNetworkReply provides a flexible and easy-to-use API for managing network requests and responses in C++ applications.