PDA

View Full Version : Real Time Plot with Qthrea,QWidget and Qwtplot



David812
27th April 2011, 10:13
Goodmorning everybody,
I'm working on an application which aquires data from HW (Reflective Memory) and plots them in a Grafic Interface.
What i tried is devolopping 2 Threads, the one in charge to aquire the data and the second one to plot data by means of a qwtplot. The problem is i could only exchange data between threads with SIGNAL/SLOT way but it's not so efficient.
I've tried to inherits qwtplot from qthread and exchange data by global variables but it creates some problem of communications between threads. :(
Any suggestions are welcome.
Thanks
Andrea

Uwe
27th April 2011, 10:35
a) Introduce a mutex guarded buffer to pass the new samples from your sampling thread to your application
b) Decouple the sampling rate and the update interval of your plot widget.

(b) means to introduce a QTimer with a reasonable interval ( depends on the amount of data you need to display ) to check periodically if there are new samples, taking them out into some other buffer and calling replot() displaying the samples of the second buffer.

Use Qwt 6.0 and check the oscilloscope example. Note that this example also shows how to paint incrementally, what makes the code much more difficult as for an application, that doesn't need to have very high refresh rates and can always do a full replot.

Uwe