Hi everyone,

Im a newbie to QT and QWT and required some help. I want to draw a real time plot for sine and cosine wave but my plot get slower and slower when time passes. Any kind soul can help me out? Thank You very much.

MainWindow Code
Qt Code:
  1. if(plottingStatus == "play")
  2. {
  3. if(angle1 == 360)
  4. {
  5. timer->stop();
  6. timer->start();
  7. }
  8. else if(angle1 <= 720)
  9. {
  10. if (timer_count%3 == 0)
  11. {
  12. angle1++;
  13. }
  14. timer_count++;
  15.  
  16. //calling the calculation function
  17. if(angle1 == 0 && rotationCount > 0)
  18. {
  19. emit toCalculate(0, timer_count, graphType, passType);
  20. }
  21. else
  22. {
  23. emit toCalculate(harmonics, timer_count, graphType, passType);
  24. }
  25.  
  26. }
  27. else
  28. {
  29. plottingStatus = "stopped1";
  30. rotationCount ++;
  31. timer->stop();
  32. angle1 = 0;
  33. timer_count = 0;
  34. }
  35. }
To copy to clipboard, switch view to plain text mode 

Sine Wave Code
Qt Code:
  1. theta1 = ((2*n)+1) * 2 * M_PI * timer_count*0.000925925;
  2. amplitude = (1.00/((2*n)+1)*1.00);
  3.  
  4. real = prev_real + (amplitude *(qCos(theta1)));
  5. img = prev_img + (amplitude*(qSin(theta1)));
  6.  
  7. Y = (timer_count*0.000925925);
  8. Y = Y;
  9.  
  10. yData.push_back(img);
  11. xData.push_back(Y);
  12.  
  13. emit graphdata(yData, xData);
To copy to clipboard, switch view to plain text mode 

Graphing code
Qt Code:
  1. cSin = new QwtPlotCurve( "y = sin(x)" );
  2. cSin->setRenderHint( QwtPlotItem::RenderAntialiased, true ); // smoothen the line of graph
  3.  
  4. cSin->setPen( QColor(Qt::green) );
  5. _yData = yData;
  6. _xData = xData;
  7.  
  8. cSin->setSamples(_xData, _yData);
  9. replot();
  10. cSin->attach( this );
To copy to clipboard, switch view to plain text mode