QNetworkAccessManager同步调用Post的方法

方法是使用让QEventLoop等待QnetworkReply的完成消息,用信号槽绑定quit以便退出循环线程,实现同步。

QNetworkAccessManager m_manager = new QNetworkAccessManager(this);
QUrl url(“http://gw.api.taobao.com/router/rest“);
QNetworkRequest
m_request = new QNetworkRequest(url);
QNetworkReply reply = manager->post(m_request, params.encodedQuery());
QEventLoop loop;
connect(m_manager, SIGNAL(finished(QNetworkReply *)), &loop, SLOT(quit()));
loop.exec();
result = reply->readAll();
delete reply;
delete m_request;
delete m_manager;