首页 > 其他分享 >QNetwork

QNetwork

时间:2023-03-12 21:56:33浏览次数:40  
标签:QNetworkAccessManager mNetworkAccessManager onReplied QNetwork QNetworkReply rep

QNetworkAccessManager* mNetworkAccessManager = new QNetworkAccessManager(this);
QUrl url = QUrl("http://"); mNetworkAccessManager->get(QNetworkRequest(url)); connect(mNetworkAccessManager, &QNetworkAccessManager::finished, this, &MainWindow::onReplied); void MainWindow::onReplied(QNetworkReply *reply) { //状态码 int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); //判断是否请求成功 if (reply->error() != QNetworkReply::NoError || statusCode != 200) { QMessageBox::warning(this, "错误", reply->errorString(), QMessageBox::Ok); } else { //解析数据 QByteArray requestData = reply->readAll(); qDebug() << requestData.data(); } //释放内存 reply->deleteLater(); }

  

标签:QNetworkAccessManager,mNetworkAccessManager,onReplied,QNetwork,QNetworkReply,rep
From: https://www.cnblogs.com/huweide/p/17209272.html

相关文章