QNetworkReply* reply = manager->get(QNetworkRequest(QUrl("http://example.com"))); QObject::connect(reply, &QNetworkReply::errorOccurred, [=]() { qDebug() << "Error occurred: " << reply->errorString(); });
QNetworkReply* reply = manager->post(QNetworkRequest(QUrl("http://example.com")), data); if(reply->error() != QNetworkReply::NoError) { qDebug() << "Error occurred: " << reply->errorString(); }In this example, a QNetworkReply object is created to send a POST request to the URL "http://example.com" with data. The error function is used to check if an error occurred during the network request, and if so, the error message is printed using the errorString function. Package library: Qt Core Library.