QT网络编程问题:访问IP地址不成功
废话不多看代码
void MainWindow::on_baidu_clicked()
{
QNetworkAccessManager *mgr = new QNetworkAccessManager(this);
QNetworkRequest url ;
//url.setUrl(QUrl("http://192.168.1.87/test")); //访问这个qdebug打印出来0
url.setUrl(QUrl("http://www.baidu.com")); //访问百度qdebug打印出来200
mgr->get(url);
QObject::connect(mgr,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));}}
void MainWindow::replyFinished(QNetworkReply *reply)
{
QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
if (statusCodeV.toInt()==200){
QTextCodec *codec = QTextCodec::codecForName("utf8");
QString all = codec->toUnicode(reply->readAll());
qDebug()<<"get return:"<<statusCodeV.toInt()<<endl;
qDebug()<<all<<endl;
ui->textEdit->setText(all);
}else{
qDebug()<<"get a error:"<<statusCodeV.toInt()<<endl;
}
reply->deleteLater();
}