I am trying to make a realtime plot and so far I got it to show a continuous sine wave, but the plot is not moving continuously on the x-axis, but more like every second it jumps one tick to the left. How can I fix this when using the QwtDateScaleDraw and QwtDateScaleEngine? I am sure it is easy, but I can not figure it out...

My code:

Qt Code:
  1. MyPlot::MyPlot(QWidget *parent) : QWidget(parent)
  2. {
  3. xData = new QList<double>();
  4. yData = new QList<double>();
  5. plot = new QwtPlot(this);
  6. layout = new QHBoxLayout();
  7.  
  8. //Add widget to layout.
  9. layout->addWidget(plot);
  10.  
  11. //Add curves.
  12. curve1 = new QwtPlotCurve("Curve 1");
  13. curve1->setSamples(xData->toVector(), yData->toVector());
  14. curve1->attach(plot);
  15.  
  16. //Set x-axis scaling.
  17. QwtDateScaleDraw *qwtDateScaleDraw = new QwtDateScaleDraw (Qt::OffsetFromUTC);
  18. QwtDateScaleEngine *qwtDateScaleEngine = new QwtDateScaleEngine(Qt::OffsetFromUTC);
  19. qwtDateScaleDraw->setDateFormat(QwtDate::Second, "hh:mm:ss");
  20. qwtDateScaleDraw->setUtcOffset(QDateTime::currentMSecsSinceEpoch() / 1000);
  21.  
  22. plot->setAxisScaleDraw ( QwtPlot::xBottom, qwtDateScaleDraw);
  23. plot->setAxisScaleEngine ( QwtPlot::xBottom, qwtDateScaleEngine);
  24. plot->setAxisMaxMajor(QwtPlot::xBottom, 0);
  25. plot->setAxisMaxMinor(QwtPlot::xBottom, 10);
  26.  
  27. //Replot.
  28. plot->replot();
  29.  
  30. //Simulated data timer.
  31. QTimer *timer = new QTimer(this);
  32. connect(timer, SIGNAL(timeout()), this, SLOT(appendData()));
  33. timer->start(1);
  34. }
  35.  
  36. void MyPlot::appendData()
  37. {
  38. static unsigned int counter = 0;
  39.  
  40. //Add new data.
  41. xData->append(counter);
  42. yData->append(sin(M_PI*( (double)counter++ / 180)));
  43.  
  44. //Remove oldest data.
  45. if (yData->size() > 1000)
  46. {
  47. xData->removeFirst();
  48. yData->removeFirst();
  49. }
  50.  
  51. //Set data.
  52. curve1->setSamples(xData->toVector(), yData->toVector());
  53.  
  54. //Replot.
  55. plot->replot();
  56. }
To copy to clipboard, switch view to plain text mode