Differentiating Between Multiple Signals Using One Slot
-
Okay, so I don't know if I'm having a brain fart and making this needlessly hard, or if what I'm proposing is the most efficient in my scenario (probably the first one).
I am using the Google Drive API to copy three different templates into one folder, which, of course– means three HTTP requests. I have written a small API client library to try and make interacting with the API use less code. The issue is when I make multiple calls to the same function of the same instance of a class (my API library), and differentiating between the responses. Looking at the response data as a means of identification is possible, but it exudes inefficiency; it doesn't feel right. Now, I could take the route of creating multiple slot functions, and making a new request as soon as another completes– but that doesn't seem like a very modular, efficient, or clean solution either. Is there some multithreading technology that I should use? -
Hi and welcome to devnet,
It looks like you want to process your requests in order so what about using a queue ? Each time one request completed you pop the next one.
-
That sounds like a similar idea to what I had, but my goal is to try and make this process as quick as possible. Would there be some way to make these requests happen concurrently and have some signal be emitted when all have completed?
-
If you are using QNetworkAccessManager you can have up to 6 parallel requests. The others will be queued.
-
Oh, interesting! How would one handle the responses in such a circumstance?
-
What do you need to do with the answers ?
-
@SGaist I am making multiple POST requests to the same API endpoint, just with different data. Each request creates a document, and each response gives back this new document's ID, which is crucial. I need to send three of these requests concurrently, and get their responses so that I can parse each ID. I can do this with one slot, but I won't know the reply's respective document. Should I have a new QThread, and have a loop checking each QNetworkReply's "finished" status- which when all are complete, emit their combined responses to a single slot?
-
You could set that information as a dynamic property of your reply that way you do not need to special handling. All the information would be in one place.
-
I think I figured it out. Thank you, I appreciate your time!