1

我想以秒为单位绘制时间sin(t)t

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();
}

这是我在文档中的代码变体:https ://www.qcustomplot.com/index.php/demos/realtimedatademo 但elapsed已经过时了,我应该改用什么?

4

1 回答 1

3

使用QElapsedTimer

static QElapsedTimer timer;
double key = timer.elapsed() / 1000.0;
于 2021-09-12T17:54:30.407 回答