Home > Enterprise >  Replace QTime::elapsed()
Replace QTime::elapsed()

Time:09-17

I want to plot sin(t) where t is time in seconds:

void MainWindow::realtimePlot()
{

    static QTime time(QTime::currentTime());
    double key = time.elapsed()/1000.0;
    QTextStream(stdout)<<(key);
    static double lastPointKey = 0;
    if(key - lastPointKey > 0.002)
    {
        ui->widget->graph(0)->addData(key, sin(key));

        lastPointKey = key;
    }

    ui->widget->graph(0)->rescaleValueAxis();
    ui->widget->xAxis->setRange(key, 4, Qt::AlignRight);
    ui->widget->replot();
}

This is my variant of code from documentation: https://www.qcustomplot.com/index.php/demos/realtimedatademo but elapsed is obsolete what should I use instead?

CodePudding user response:

Use QElapsedTimer:

static QElapsedTimer timer;
double key = timer.elapsed() / 1000.0;
  • Related