Qt synchronous QNetworkAccessManager get

别来无恙 提交于 2019-12-04 09:34:51

Yum may use something like this:

QEventLoop loop;
connect(_netReply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();

The simple solution mentioned in the wiki and in the answer from yttrium is quite fragile since it doesn't handle all possible failure scenarios (such as proxy) and therefore shouldn't be used in a production environment, and unfortunately it has become quite prolific, so anyone asking for synchronous QNAM simply get stumped by "use it asynchronoysly [stupid]" or this simple piece of code that will eventually fail.

I haven't found a "proper" solution made by the Qt team themselves, but this guy on codeproject has been decent enough to make a more comprehensive wrapper that should be a lot safer:
http://www.codeproject.com/Articles/484905/Use-QNetworkAccessManager-for-synchronous-download

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