首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么QCustomPlot绘制大数据的速度太慢?

为什么QCustomPlot绘制大数据的速度太慢?
EN

Stack Overflow用户
提问于 2020-10-22 19:19:25
回答 1查看 603关注 0票数 3

我想画一些大的数据块(3k),每100毫秒来一次。我尝试了QCustomPlotQwt与确切的3k点,我得到了非常好的性能绘图与Qwt和非常糟糕的性能与QCustomPlot。我认为我在QCustomPlot中的行为是错误的,我使用这段代码在QCustomPlot中进行绘图(这个例子来自于QCustomPlot绘图--我编辑了函数setupQuadraticDemo):

代码语言:javascript
复制
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);
}

这段代码值为Qwt.我对QCustomPlot做错了吗?为什么策划得太慢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-22 20:41:39

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

代码语言:javascript
复制
std::srand(std::time(nullptr));

这一行将强制rand()的种子在一个确定的时间内被固定(如果我想精确地说,您的种子值是为1 second固定的),所以无论数据本身是否被更新,您都看不到任何更改,因为重绘将在该持续时间内绘制相同的点(1 sec)。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64489118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档