I'm want to draw a sinusoid that is updated every 100ms after a button is clicked. What I'm doing is, when the button is clicked, 2000 points are plotted with x and y values equal 0 and then, the timer is started. Every tick of the clock updates the plot, "moving" all the values to the left (what will remove the first value of the series) and adding a new valeu to the end.
I make this but the plot just don't update. I'm sure the problem isn't with the Timer.
PS: sorry for my English.
Global variables:
double i;
double i;
QwtPlotCurve *curve;
QwtPlotGrid *grid;
QPolygonF points;
QPointF point;
To copy to clipboard, switch view to plain text mode
Event button clicked:
void MainWindow::on_btnDraw_clicked()
{
i=0;
ui->qwtPlot->setTitle("Test Plot");
ui->qwtPlot->setCanvasBackground(Qt::white);
ui
->qwtPlot
->setAxisScale
(QwtPlot::yLeft,
-2.0,
2.0);
ui
->qwtPlot
->setAxisScale
(QwtPlot::xBottom,
0.0,
20.0);
ui->qwtPlot->updateAxes();
curve->setPen(Qt::blue,1);
curve
->setRenderHint
(QwtPlotItem::RenderAntialiased,
true);
grid->show();
grid->attach(ui->qwtPlot);
for(i=0;i<2000;i++)
{
point.setX(0);
point.setY(0);
points += point;
}
curve->setSamples(points);
curve->attach(ui->qwtPlot);
ui->qwtPlot->update();
timer->setInterval(100);
timer->start();
connect(timer,SIGNAL(timeout()),this,SLOT(Update()));
}
void MainWindow::on_btnDraw_clicked()
{
i=0;
ui->qwtPlot->setTitle("Test Plot");
ui->qwtPlot->setCanvasBackground(Qt::white);
ui->qwtPlot->setAxisScale(QwtPlot::yLeft, -2.0, 2.0);
ui->qwtPlot->setAxisScale(QwtPlot::xBottom, 0.0, 20.0);
ui->qwtPlot->updateAxes();
curve = new QwtPlotCurve("Points");
curve->setPen(Qt::blue,1);
curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
grid = new QwtPlotGrid();
grid->show();
grid->attach(ui->qwtPlot);
for(i=0;i<2000;i++)
{
point.setX(0);
point.setY(0);
points += point;
}
curve->setSamples(points);
curve->attach(ui->qwtPlot);
ui->qwtPlot->update();
timer = new QTimer(this);
timer->setInterval(100);
timer->start();
connect(timer,SIGNAL(timeout()),this,SLOT(Update()));
}
To copy to clipboard, switch view to plain text mode
Update() function:
void MainWindow::Update()
{
ui
->qwtPlot
->setAxisAutoScale
(QwtPlot::yLeft,
true);
ui
->qwtPlot
->setAxisAutoScale
(QwtPlot::xBottom,
true);
ui->qwtPlot->updateAxes();
for(int j=0;j<points.count()-1;j++)
{
points.value(i)=points.value(i+1);
}
i+=0.1;
point.setX(i);
point.setY(sin(i));
points += point;
curve->setSamples(points);
curve->attach(ui->qwtPlot);
ui->qwtPlot->update();
}
void MainWindow::Update()
{
ui->qwtPlot->setAxisAutoScale(QwtPlot::yLeft, true);
ui->qwtPlot->setAxisAutoScale(QwtPlot::xBottom, true);
ui->qwtPlot->updateAxes();
for(int j=0;j<points.count()-1;j++)
{
points.value(i)=points.value(i+1);
}
i+=0.1;
point.setX(i);
point.setY(sin(i));
points += point;
curve->setSamples(points);
curve->attach(ui->qwtPlot);
ui->qwtPlot->update();
}
To copy to clipboard, switch view to plain text mode
Bookmarks