我想画一些大的数据块(3k),每100毫秒来一次。我尝试了QCustomPlot和Qwt与确切的3k点,我得到了非常好的性能绘图与Qwt和非常糟糕的性能与QCustomPlot。我认为我在QCustomPlot中的行为是错误的,我使用这段代码在QCustomPlot中进行绘图(这个例子来自于QCustomPlot绘图--我编辑了函数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);
}这段代码值为Qwt.我对QCustomPlot做错了吗?为什么策划得太慢?
发布于 2020-10-22 20:41:39
我猜问题的根源在于代码本身。您正在以错误的方式更新点数。您必须从代码中删除下面一行
std::srand(std::time(nullptr));这一行将强制rand()的种子在一个确定的时间内被固定(如果我想精确地说,您的种子值是为1 second固定的),所以无论数据本身是否被更新,您都看不到任何更改,因为重绘将在该持续时间内绘制相同的点(1 sec)。
https://stackoverflow.com/questions/64489118
复制相似问题