[Solved]Asynchronous and signal and slot
-
@
QNetworkReply *reply = manager->get(QUrl("xxx"));connect(reply, SIGNAL(finished()), this, SLOT(some_slot()) );
@when I call manager->get, the QNetworkAccessManager will fetch the data from web
And then I connect the signal to slot
what if the reply already fetch all of the data before the connection establish? -
The only way any other code could be executed between those lines is when you have multiple threads and the scheduler stops the main thread right after the first line, executes some of the other thread, and returns back to execute the second line.
However, if this is the case, Qt will use Queued Connections for signaling. So even if the other thread emits a signal in between those lines, the main thread will receive this signal in the next iteration of the event loop in the main thread, which comes after the function that contains those two lines.
And if there are no other threads involved, you also don't need to worry. Because then it's impossible that any other code is executed in between the two lines anyway.
-
Thank you very much, don't know how Qt make this work
I will treat it as some kind of "black magic" for now