【问题标题】:Replace QTime::elapsed()替换 QTime::elapsed()
【发布时间】:2021-11-08 05:26:31
【问题描述】:

我想绘制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 已经过时了,我应该改用什么?

【问题讨论】:

    标签: c++ qt qt6


    【解决方案1】:

    使用QElapsedTimer:

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

    【讨论】:

      猜你喜欢
      • 2013-05-05
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-19
      相关资源
      最近更新 更多