转换函数
QString str;
QString str = QString::fromUtf8(str.toLatin1());
*********************************
开始
.pro 添加 QT += network
.h 添加
#include <QNetworkReply>
private slots:
void replyFinished(QNetworkReply*);
.cpp 添加
初始执行
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://127.0.0.1/")));
实现槽
void MainWindow::replyFinished(QNetworkReply* p){
QByteArray a1 = p->readAll();
QString str;
str.prepend(a1);
ui->plainTextEdit->appendHtml(QString::fromUtf8(str.toLatin1()));
}