Having some problem figuring out how to do this. Will try and explain what it is that I’m trying to do first.
First I have this class which contains a Read-Only file. This class will use a this other class(StorageProvider) to upload blocks of this file. That class contains a QNetworkAccessManager. When uploading blocks of the file, I will send the block to the StorageProvider class that then uses a REST request that it sends of to the QNAM. When the QNetworkReply is done, the StorageProvider will then signal this to the uploader (so that it know that that block is done).
Uploader -> StorageProvider -> QNetworkAccessManager -> Internet
So far so good right? I could just put a slot in the uploader that listens to when the StorageHandler is done with the request that it made on the QNAM.
However, since the QNAM can, over HTTP, do 6 requests at the same time, I was thinking to make it so that when the StorageProvider signals that it is done with a block, and unique BlockId is connected to the signal, allowing the uploader to know WHICH block that is done, not just that it IS done.
This would mean that the slot that will be called whenever a signal(blockId) is emitted by the StorageProvider, will have to store the id that was done and then look for a new one that is not uploaded (Forgot to mention that I have a list of IDs that are already uploaded, so when it steps though the ids (0…1000), it also needs to 1. push the index of the file 4mb forward 2. check in the list of already existing block if it is in.
So, my question is: If I have a slot which increses a “currentBlockId” by one until it finds the next one that can be upload + reads the file 4mb at the time until we are at position “currentBlockId” * 4mb (the index in the file will be pushed forward like an index and it will not be random access. when this index reaches the end of the file we are done) and this slot will be called whenever one of 5 uploads are done, will I have an issue? The reason why I’m asking is beacuse the QNAM makes it calls in different threads which might do so that 2-5 “finished()” signals are emitted at the same time, which would call the slot that handles that at the same time? Like, I’m not too sure what will happen then. Notice that none of my code is threaded and in theory the signals should be queued right? and the slot would be called 5 times, one after another?
Thanks
Wow, my eyes. Read through that once, still don’t have a handle on what you want… so here’s the scoop.
By default, slots are called on the event thread. By default, there is only one event thread. In this regard, you are correct. By default, when a slot is consuming the event thread, the calls queue up for later.
However, that does not mean it’s safe to assume that all 5 of your calls will necessarily arrive in the order that you expect them to, or even from the same thread. If you want to get fancy and process stuff in parallel (can’t tell, the post is too confusing), then use QtConcurrent::run() for just one example of how to launch a new thread for processing. Under this scheme, all the slot would do is push your data onto a queue (remember to protect it with a mutex) and fire off the QtConrrent::run() function.