Qt - How to get responseText with QNetworkAccessmanager
-
19-02-2021 - |
Question
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!
Solution
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.
OTHER TIPS
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.