警告:‘elapsed’已弃用:改用QElapsedTimer

我在用Qt5编程实现Qcustomplot绘制动态波形图时,用的是qcustomplot官网给的example修改的程序,但是在Qt Creator编译的时候提示了一个警告,意思是:‘elapsed’已弃用:改用QElapsedTimer
下面是我的一部分源码和这段源码提示的警告,在网上搜了一下,还是没找到解决方法

源码:

void waveform_display::realtimeDataSlot()
{
    static QTime time(QTime::currentTime());
    // calculate two new data points:
    double key = time.elapsed()/1000.0; // 开始到现在的时间,单位秒
    static double lastPointKey = 0;
    if (key-lastPointKey > 0.002) // 大约2ms添加一次数据
    {
      //添加数据到graph
      customPlot->graph(0)->addData(key, array.toDouble());
      customPlot->graph(1)->addData(key, ((array).toDouble())*2);
     // 重新划分值(垂直)轴以适合当前数据:
      customPlot->graph(0)->rescaleValueAxis();
      customPlot->graph(1)->rescaleValueAxis();
     //记录当时的时刻
      lastPointKey = key;
    }
    // 曲线能动起来的关键在这里,设定x轴范围为最近10个时刻
    customPlot->xAxis->setRange(key, 10, Qt::AlignRight);
    //绘图
    customPlot->replot();
    //计算帧数
    static double lastFpsKey;
    static int frameCount;
    ++frameCount;
    if (key-lastFpsKey > 2) //每2秒求一次平均值
    {
        //状态栏显示帧数和数据总数
        ui->statusBar->showMessage(QString("%1 FPS, Total Data points: %2")
                                   .arg(frameCount/(key-lastFpsKey), 0, 'f', 0)
                                   .arg(customPlot->graph(0)->data()->size()+customPlot->graph(1)->data()->size())
                                   , 0);
        lastFpsKey = key;
        frameCount = 0;
    }
}

警告:

waveform_display.cpp:93:23: warning: 'elapsed' is deprecated: Use QElapsedTimer instead
qdatetime.h:230:5: note: 'elapsed' has been explicitly marked deprecated here
qglobal.h:294:33: note: expanded from macro 'QT_DEPRECATED_X'
qcompilerdetection.h:676:55: note: expanded from macro 'Q_DECL_DEPRECATED_X'

你可以看看这里有没有你要的答案: QT应用编程: 使用qcustomplot显示动态曲线、设计心电图显示页面_DS小龙哥的专栏-CSDN博客 一、环境介绍操作系统:win10 64位QT版本:QT5.12.6编译器:MinGW 32二、功能介绍软件端接收设备上传的心电数据、运动数据、体温数据进行处理、存储显示。完整项目源码下载链接:https://download.csdn.net/download/xiaolong1126626497/18607424三、核心代码3.1 widget.cpp#include "widget.h"#include "ui_widget.h"#de... https://blog.csdn.net/xiaolong1126626497/article/details/116694318

这里 一、环境介绍操作系统:win10 64位QT版本:QT5.12.6编译器:MinGW 32二、功能介绍软件端接收设备上传的心电数据、运动数据、体温数据进行处理、存储显示。完整项目源码下载链接:https://download.csdn.net/download/xiaolong1126626497/18607424三、核心代码3.1 widget.cpp#include "widget.h"#include "ui_widget.h"#de... https://blog.csdn.net/xiaolong1126626497/article/details/116694318

之前给妇幼做的胎心监测仪项目,用的就是Qcustomplot,都很正常。 版本QT5.12.6。

QTime 改成QElapsedTimer就好了