View Full Version : Updating QPlot's curve with Qthread

24th May 2011, 18:04
Pardon me, I am new here.

There's been similar threads with similar problem, but there's yet real answer.

I have a class which contains both QwtPlot, QwtPlotCurve and its array of data. I have certain function to update 'em.

Calling the function manually yields the desired result: last value of graph is updated while data are shifted to 'front'.



But using QThread (which I badly need to update the plot realtime), after I started the thread, the plot's just updated once. It's also no luck with me with QTimer timeout() signal--it yields similar result.

class graphthread : public QThread{
graphs *yeah;

graphthread(graphs *hereitis){

void run(){
while (1){
// printf("%f\n",yeah->getValue()); // the plot won't update but this's repeatedly printed

note that there's little elevation in the rightmost

'd anyone like to show me where I am doing wrong?
Any help would be appreciated. ;)

Santosh Reddy
25th May 2011, 07:34
I am not very sure of Qwt, but I thing I suspect is that, "graphs *hereitis" is the QThread's constructor parameter which is stored in "yeah" member variable, an then it is used later in the context of the QThread.

Now internally yeah->updateCurve(..) might be emitting some signals which need to propagated to the GUI thread, only then the graph will be updated. You may not be able to make signals work until the "graphs" object (yeah) is created in the context of the working Thread, or at least the working thread has the ownership.

26th May 2011, 03:44
Ah, yep. So I need to make SIGNAL which triggers certain GUI-related (widget) SLOT?
And I am sorry, the variable names should have been clearer :o

Santosh Reddy
26th May 2011, 04:42
I mean who is owner of the graph, QwtPlot and QwtPlotCurve class objects?

27th May 2011, 14:18
The 'owner' the QwtPlot, QwtPlotCurve is a class I made myself.

After reading queuedcustomtype example, it's clear to me: I need to make a SIGNAL in a thread to pass some value to a SLOT of widget which has that 'updating' thread :) So every self-updating widget has to have its own thread within?

Thanks, Santosh Reddy

ummh, it's just embarrassing that the title is QPlot instead of QwtPlot, duh!

1st June 2011, 11:15
For any type of "realtime" plot I strongly recommend to decouple the refresh rate of your plot widget from the sample rate.

Use a QTimer, that periodically checks if new samples have been collected and calls replot then.