Pregunta

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 :)

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top