What is the parallelization mechanism in QNetworkAccessManager?

不问归期 提交于 2019-12-08 04:34:20

问题


I am writing an HTTP access module for VLC 2.0 using QtNetwork from Qt 4.7.4. My code snips follow:

static int Open(vlc_object_t *p_this)
{
  ....
  QNetworkAccessManager *nam = new QNetworkAccessManager;
  QNetworkReply *reply = nam->get(QNetworkRequest("http://stackoverflow.com/"));
  Q_ASSERT(reply);

  QEventLoop loop;
  connect(reply, SIGNAL(finished()), &loop, SLOT(quit());
  connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), &loop, SLOT(quit()));
  connect(reply, SIGNAL(readyRead()), &loop, SLOT(quit()));
  loop.exec(); // -- BLOCKED HERE in Lion
  ....
}

The same code works well on Windows 7, but would get blocked on OS X Lion. The event loop after exec() never quit(). I also tried accessing reply->bytesAvailable() from another thread, which always returned 0. I guess the reason could be related to the parallel mechanism in QNetworkAccessManager, when nam couldn't get any time slots to work after the parent thread was blocked by QEventLoop.

Could anyone give me some suggestions why event loop would get blocked only on Mac, and what I could do to bypass such issue to make QNetworkAccessManager to work without creating another QThread?

BTW, the Qt being used is the latest version on macports built with Carbon framework (qt4-mac).


回答1:


You may have to make periodic calls to QApplication::processEvents() to get the job done.



来源:https://stackoverflow.com/questions/9506852/what-is-the-parallelization-mechanism-in-qnetworkaccessmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!