
背景:處理海量波形數(shù)據(jù)如錄波分析時核心痛點在于“文件讀取慢”、“內(nèi)存易溢出”以及“UI渲染卡頓”。環(huán)境安裝與配置官網(wǎng)https://www.qcustomplot.com/index.php/QCustomPlot可直接從官網(wǎng)下載在工程中引入.h .cpp就可以此外官網(wǎng)也提供了幾個示例程序可參考。引用這個庫需要在pro文件加入QT printsupport// mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include QMainWindow #include qcustomplot.h namespace Ui { class MainWindow; } class QCustomPlot; class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent nullptr); ~MainWindow(); void setupQuadraticDemo(QCustomPlot *customPlot); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H#include mainwindow.h #include ui_mainwindow.h MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui-setupUi(this); QCustomPlot* customPlot new QCustomPlot; setCentralWidget(customPlot); setupQuadraticDemo(customPlot); } MainWindow::~MainWindow() { delete ui; } void MainWindow::setupQuadraticDemo(QCustomPlot *customPlot) { QVectordouble x(101), y(101); for (int i 0; i 101; i) { x[i] i / 50.0 - 1; // -1 到 1 y[i] x[i] * x[i]; } customPlot-addGraph(); // 添加一個曲線圖QGraph customPlot-graph(0)-setData(x, y); // 為曲線圖添加數(shù)據(jù) customPlot-graph(0)-setName(QString::fromLocal8Bit(customplot_quadratic_demo)); // 設(shè)置曲線圖的名字 customPlot-xAxis-setLabel(x); // 設(shè)置x和y軸的標簽 customPlot-yAxis-setLabel(y); customPlot-xAxis-setRange(-1, 1); // 設(shè)置x軸的范圍為(-1,1) customPlot-yAxis-setRange(0, 1); customPlot-legend-setVisible(true); // 顯示圖例 }