c++ - 为什么 QCustomPlot 在绘制大数据时速度太慢?

标签 c++ qt gcc qwt qcustomplot

我想绘制每 100 毫秒出现的大量数据 (3k)。我试过 QCustomPlotQwt精确的 3k 点,我在使用 Qwt 绘图时表现非常好,而使用 QCustomPlot 时表现非常糟糕。我认为我在使用 QCustomPlot 时行为不当,我使用此代码在 QCustomPlot 中绘图(此示例来自 QCustomPlot plot-examples,我编辑了函数 setupQuadraticDemo):

void  MainWindow::setupQuadraticDemo(QCustomPlot *customPlot)
{
 demoName = "Quadratic Demo";
 customPlot->addGraph();
 customPlot->setNotAntialiasedElements(QCP::AntialiasedElement::aeAll);

 customPlot->xAxis->setRange(0, 1000);
 customPlot->yAxis->setRange(0, 1000);

 customPlot->xAxis->setLabel("x");
 customPlot->yAxis->setLabel("y");

 connect(&dataTimer, &QTimer::timeout, this, [customPlot]
 {
  constexpr auto length = 3000;
  QVector<double> x(length), y(length);

  std::srand(std::time(nullptr));

  for (int i = 0; i < length; ++i)
  {
   x[i] = std::rand() % 1000;
   y[i] = std::rand() % 1000;
  }

  customPlot->graph(0)->setData(x, y, true);

  customPlot->replot();
 });

 dataTimer.start(100);
}

this code对于 Qwt。我对 QCustomPlot 做错了吗?为什么绘图速度太慢?

最佳答案

我想问题的根源在于代码本身。您正在以错误的方式更新点。您必须从代码中删除以下行

std::srand(std::time(nullptr));

此行将强制 rand() 的种子在确定的时间内固定(如果我想准确地说,您的种子值固定为 1 秒 ),因此无论数据本身是否更新,您都看不到任何变化,因为重绘将在该持续时间内绘制相同的点(1 sec)。

关于c++ - 为什么 QCustomPlot 在绘制大数据时速度太慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64489118/

相关文章:

c++ - x86-64 汇编程序中的无限循环

GCC 命令行参数挑剔

c++ - 如何将 vector 从存储库返回到服务层

c++ - 如何将类成员函数的返回类型设置为私有(private)结构的对象

Eclipse、QT 和 "C++ project": is it possible?

c++ - Qt QTcpSocket 异步写入

c++ - 如何检查鼠标在最后 5 秒内没有移动?

c++ - 为什么 setjmp 不保存堆栈?

c++ - Qt atomic int 获取并立即设置

linux - 使用另一个共享库创建一个共享库