PDA

View Full Version : Limit queue size of Qt::QueuedConnection



jdbug1
16th May 2017, 10:30
Hey,

I have a very simple question which seems to be complicated to solve. Google didn't help me, so here is my problem:

I have a camera thread which is constantly emitting a signal with the current picture at 29Hz.
Also, I have a worker within a worker thread which should receive the picture and process it somehow.

My current implementation of the worker can process frames at ~5-10Hz. Since I don't care about every single frame I want the worker to process always the most recent frame.
I also want the threads to be completely independent, so I can't use Qt::DirectConnection (which is thread-wise stupid anyways) and I don't want the worker to poll a picture once it is done processing.

Is there any way to limit the queue size to contain only one element which is the most recent one?

Thank you in advance!

Lesiok
16th May 2017, 10:41
In slot connected to signal from camera only append new picture to some list. After that start method processing pictures with QTimer::singleShot. Signals from QTimer are serviced after all another signals. In this method do the work of the last picture and clear the list. Remember to synchronize by semaphores.

jdbug1
17th May 2017, 11:30
Thank you, I will try that!