【发布时间】:2021-02-05 21:01:50
【问题描述】:
我想绘制每 100 毫秒出现的大量数据 (3k)。我尝试了 QCustomPlot 和 Qwt 精确的 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 做错了吗?为什么绘图速度太慢了?
【问题讨论】:
-
您不需要在每次重绘时重新分配向量。什么是“太慢”?你测量过重绘需要多长时间吗?
-
我用 Qwt 做我所做的事情,是的,我测量重绘需要多长时间。
标签: c++ qt gcc qwt qcustomplot