Hi there,

I have a problem with dynamically updating a QwtPlot. I based my code on the example "data_plot" but instead of having a timer inside of my data_plot-object I created a slot which gives me new values to add. Here is the code:

Qt Code:
  1. #ifndef _DATA_PLOT_H
  2. #define _DATA_PLOT_H 1
  3.  
  4. #include <qwt_plot.h>
  5.  
  6. const int PLOT_SIZE = 201; // 0 to 200
  7.  
  8. class DataPlot : public QwtPlot
  9. {
  10. Q_OBJECT
  11.  
  12. public:
  13. DataPlot(QWidget* = NULL);
  14.  
  15. public slots:
  16. void refreshP(double val);
  17.  
  18. private:
  19.  
  20. double d_x[PLOT_SIZE];
  21. double d_y[PLOT_SIZE];
  22. double d_z[PLOT_SIZE];
  23. };
  24.  
  25. #endif
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include <stdlib.h>
  2. #include <qwt_painter.h>
  3. #include <qwt_plot_canvas.h>
  4. #include <qwt_plot_marker.h>
  5. #include <qwt_plot_curve.h>
  6. #include <qwt_scale_widget.h>
  7. #include <qwt_legend.h>
  8. #include <qwt_scale_draw.h>
  9. #include <qwt_math.h>
  10. #include "data_plot.h"
  11. #include <iostream>
  12.  
  13. DataPlot::DataPlot(QWidget *parent): QwtPlot(parent)
  14. {
  15.  
  16. // Disable polygon clipping
  17. QwtPainter::setDeviceClipping(false);
  18.  
  19. // We don't need the cache here
  20. canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
  21. canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
  22.  
  23.  
  24. // Initialize data
  25. for (int i = 0; i< PLOT_SIZE; i++)
  26. {
  27. d_x[i] = 0.5 * i; // time axis
  28. d_y[i] = 0;
  29. }
  30.  
  31. // Insert new curves
  32. QwtPlotCurve *cRight = new QwtPlotCurve("Data Moving Right");
  33. cRight->attach(this);
  34.  
  35. // Set curve styles
  36. cRight->setPen(QPen(Qt::red));
  37.  
  38. // Attach (don't copy) data. Both curves use the same x array.
  39. cRight->setRawData(d_x, d_y, PLOT_SIZE);
  40.  
  41. }
  42.  
  43. // Generate new values
  44. void DataPlot::refreshP(double val)
  45. {
  46. for ( int j = 0; j < PLOT_SIZE - 1; j++ )
  47. d_y[j] = d_y[j+1];
  48.  
  49. d_y[PLOT_SIZE - 1] = val;
  50. // update the display
  51. replot();
  52.  
  53. }
To copy to clipboard, switch view to plain text mode 

Then here is how it is used:

Qt Code:
  1. #include "window.h"
  2.  
  3. Window::Window(QWidget *parent) : QWidget(parent)
  4. {
  5. .
  6. .
  7. .
  8. Widget2D *evolving_obj = new Widget2D;
  9. DataPlot *dynamics = new DataPlot(this);
  10. connect(evolving_obj, SIGNAL(newSignal(double)), dynamics, SLOT(replot())); // this does not work
  11. connect(someButton , SIGNAL(clicked()), dynamics, SLOT(replot())); //this works!
  12.  
  13. .
  14. .
  15. .
  16. }
To copy to clipboard, switch view to plain text mode 

Widget2D has a timer and produces data and of course Widget2D has a signal "void newSignal(double nS);" with the corresponding body. The new data is correctly stores in the array d_Y but the plot is not updated.

If I however click on the someButton, the plot is updated.

I have no clue how to solve this problem. Thanks for your help.