Make QNAM not sent any new request, until the last requests' response has arrived.
-
Hello,
I am working on a Qt application using C++.
I need to make http requests through my application, so i am using QNetworkAccessManager for the REST api calls.I need the asynchrounous behavior which the QNAM provides, but there is one use case in which i would like the QNAM to wait and not sent any new requests, until the last requests has returned.
How do i acheive that?
-
Hi,
Can you explain how you define that the QNAM has to start waiting ?
-
@Rizwan94 said in Make QNAM not sent any new request, until the last requests' response has arrived.:
i would like the QNAM to wait and not sent any new requests, until the last requests has returned.
Each time you get a completed reply, the
QNetworkReply
object emits afinished()
signal.Make your app listen for these
finished()
signals. Do not callQNetworkAccessManager::get()
orpost()
until you have received the last signal. -
@JKSH Thank you for your response.
I am currently connecting to the replyFinished signal of the QNAM but not the QNetworkReply.
I will try if your suggested approach works fine with replyFinished of QNAM.Also, I am concerned if the UI hangs when I am not processing any further requests.
Example :
When button1 is clicked, I send the request1 and wait for the response. What if the user in meantime clicks on the button2 which does another request2 ? Won't the UI hang?Am sorry for adding multiple questions in this comment.
Let me know if you need further info -
@Rizwan94 said in Make QNAM not sent any new request, until the last requests' response has arrived.:
I am concerned if the UI hangs
If you're using signals/slots then the UI will not hang (do not wait "actively" using any "wait*" methods or loops).
"When button1 is clicked, I send the request1 and wait for the response" - how do you "wait"? With signals/slots you do not have to wait and block anything.