QWT实时数据显示

1.设置.pro中的参数

DEFINES += QT_DEPRECATED_WARNINGS\

            QT_DLL\
            QWT_DLL
LIBS += -L"D:\Qt\Qt5.7.1\5.7\mingw53_32\lib" -lqwtd
LIBS += -L"D:\Qt\Qt5.7.1\5.7\mingw53_32\lib" -lqwt
INCLUDEPATH += D:\Qt\Qt5.7.1\5.7\mingw53_32\include\Qwt
2.引入相应的类

    #include <QDateTime>

#include <QTimer>
#include <QVector>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_magnifier.h>
#include <qwt_plot_panner.h>
#include <qwt_legend.h>

3.  创建对象并实例化对象

QwtPlotCurve * curve;

         curve = new QwtPlotCurve("Acc_X");

   //加载数据
   curve->setSamples(time, val, 10);
   //加到plot,plot由IDE创建
   curve->attach(ui->qwtPlot);
       QTimer *timer = new QTimer( this);
 
 
   //新建定时器
   connect(timer,SIGNAL(timeout()),this,SLOT(timerEvent2()));
void MainWindow::timerEvent2() {
   //time,val值定义为全局变量。
    //重新加载数据
     curve->setSamples(time, val, 10);
  //  curve->setdata(time,val);
    //QwtPlot重绘,重要,
    ui->qwtPlot->replot();
}

猜你喜欢

转载自blog.csdn.net/csu_guo_liang/article/details/79019662