Qt signal slot connection - QNetworkAccessManager

徘徊边缘 提交于 2019-11-28 08:56:19

问题


Im new in Qt and im trying to understand the following signal-slot connection:

m_networkManager = new QNetworkAccessManager(this);
QNetworkReply *reply = m_networkManager->get(request);
connect(reply, SIGNAL(finished()),this, SLOT(onRequestCompleted()));

Why we connect the "finished" signal after the get-request?...What happened, if the network connection in line-2 was faster executed before the slot connection (line-3) was made?

I know, that this code will work. but i want to understand how this is possible :)


回答1:


It's not possible for the finished() signal to emit because you haven't yielded to the event loop yet. Even if somehow the get request got sent and then came back, your code is still executing and will continue to execute until you've yielded to the event loop. Only then will the reply object ever get a chance to actually do anything, such as parsing the get response and emitting the corresponding signal.



来源:https://stackoverflow.com/questions/16627573/qt-signal-slot-connection-qnetworkaccessmanager

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