我在用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'
之前给妇幼做的胎心监测仪项目,用的就是Qcustomplot,都很正常。 版本QT5.12.6。
QTime 改成QElapsedTimer就好了