问题
Here is my code:
Widget::Widget()
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://qt.nokia.com")));
}
void Widget::replyFinished(QNetworkReply* reply)
{
//some other code here
}
I hope that reply will have some method like getrespnsetext() but it not...
Can some one show me an example, all the thing i need is print out the response text (is ther any way like in Javascript Ajax)
Thanks for your help!
回答1:
You only need to use reply->readAll()
inside the replyFinished(...)
function to read all the returned text. It returns a QByteArray
, so you can do wathever you want from there.
回答2:
Looking at the documentation for QNetworkReply
here, specifically at the finished signal, it mentions that you can use readAll()
to get a QByteArray
of all of the data. Assuming that you know whether or not such a conversion is valid, QString
does have a constructor that takes a QByteArray
as a parameter, as documented here.
来源:https://stackoverflow.com/questions/7981239/qt-how-to-get-responsetext-with-qnetworkaccessmanager