Qt - How to get responseText with QNetworkAccessmanager

nvcnvn picture nvcnvn · Nov 2, 2011 · Viewed 9.4k times · Source

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!

Answer

felixgaal picture felixgaal · May 8, 2012

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.