Here's how I do it:
Add a signal to the workflows that are emitted each time a new batch of data is ready. Connect this signal to the slot defined in the main graphics stream using Qt :: QueuedConnection. This slot should collect processed data from workflows and insert them into the table. The model should also appear naturally in the GUI thread.
Update 1
More detailed explanation. You already have threads, so all you have to do is expand them a bit. Example:
We have a workflow. Now about the GUI thread:
- Create your workflow objects.
- Connect the
dataBatchReady() signal to the slot in the GUI stream. Remember to use Qt::QueuedConnection . - Run threads.
- When this slot runs, you need to find out which workflow contains the new data. You can put them all (not very efficiently), or you can add an additional method to the worker to find out if the
dataBatch field dataBatch not empty. You can also come up with another way to find out which thread emitted the signal - what you need to find out. - When you
popLastBatch() out the stream, just call popLastBatch() on that stream and add the returned list to the model. The model takes care of the rest. If you still have performance issues, check out tHand's request.
Note. I have not tested the code so that it may contain some obvious errors. You must understand this idea.
source share