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
if(plottingStatus == "play")
{
if(angle1 == 360)
{
timer->stop();
timer->start();
}
else if(angle1 <= 720)
{
if (timer_count%3 == 0)
{
angle1++;
}
timer_count++;
//calling the calculation function
if(angle1 == 0 && rotationCount > 0)
{
emit toCalculate(0, timer_count, graphType, passType);
}
else
{
emit toCalculate(harmonics, timer_count, graphType, passType);
}
}
else
{
plottingStatus = "stopped1";
rotationCount ++;
timer->stop();
angle1 = 0;
timer_count = 0;
}
}
if(plottingStatus == "play")
{
if(angle1 == 360)
{
timer->stop();
timer->start();
}
else if(angle1 <= 720)
{
if (timer_count%3 == 0)
{
angle1++;
}
timer_count++;
//calling the calculation function
if(angle1 == 0 && rotationCount > 0)
{
emit toCalculate(0, timer_count, graphType, passType);
}
else
{
emit toCalculate(harmonics, timer_count, graphType, passType);
}
}
else
{
plottingStatus = "stopped1";
rotationCount ++;
timer->stop();
angle1 = 0;
timer_count = 0;
}
}
To copy to clipboard, switch view to plain text mode
Sine Wave Code
theta1 = ((2*n)+1) * 2 * M_PI * timer_count*0.000925925;
amplitude = (1.00/((2*n)+1)*1.00);
real = prev_real + (amplitude *(qCos(theta1)));
img = prev_img + (amplitude*(qSin(theta1)));
Y = (timer_count*0.000925925);
Y = Y;
yData.push_back(img);
xData.push_back(Y);
emit graphdata(yData, xData);
theta1 = ((2*n)+1) * 2 * M_PI * timer_count*0.000925925;
amplitude = (1.00/((2*n)+1)*1.00);
real = prev_real + (amplitude *(qCos(theta1)));
img = prev_img + (amplitude*(qSin(theta1)));
Y = (timer_count*0.000925925);
Y = Y;
yData.push_back(img);
xData.push_back(Y);
emit graphdata(yData, xData);
To copy to clipboard, switch view to plain text mode
Graphing code
cSin
->setRenderHint
( QwtPlotItem::RenderAntialiased,
true );
// smoothen the line of graph
cSin
->setPen
( QColor(Qt
::green) );
_yData = yData;
_xData = xData;
cSin->setSamples(_xData, _yData);
replot();
cSin->attach( this );
cSin = new QwtPlotCurve( "y = sin(x)" );
cSin->setRenderHint( QwtPlotItem::RenderAntialiased, true ); // smoothen the line of graph
cSin->setPen( QColor(Qt::green) );
_yData = yData;
_xData = xData;
cSin->setSamples(_xData, _yData);
replot();
cSin->attach( this );
To copy to clipboard, switch view to plain text mode
Bookmarks