大数据量导致曲线绘制卡顿问题
这里提供一个思路在跟踪源码中发现底层卡顿在vector的resize() 此处扩容中
所以尽量使用下面的接口文章来源:https://www.toymoban.com/news/detail-682667.html
/*! \overload
Adds the provided data point as \a key and \a value to the current data.
Alternatively, you can also access and modify the data directly via the \ref data method, which
returns a pointer to the internal data container.
*/
void QCPGraph::addData(double key, double value)
{
mDataContainer->add(QCPGraphData(key, value));
}
而不是使用addData这个接口,还有setData这个接口文章来源地址https://www.toymoban.com/news/detail-682667.html
/*! \overload
Adds the provided points in \a keys and \a values to the current data. The provided vectors
should have equal length. Else, the number of added points will be the size of the smallest
vector.
If you can guarantee that the passed data points are sorted by \a keys in ascending order, you
can set \a alreadySorted to true, to improve performance by saving a sorting run.
Alternatively, you can also access and modify the data directly via the \ref data method, which
returns a pointer to the internal data container.
*/
void QCPGraph::addData(const QVector<double> &keys, const QVector<double> &values, bool alreadySorted)
{
if (keys.size() != values.size())
qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size();
const int n = qMin(keys.size(), values.size());
QVector<QCPGraphData> tempData(n);
QVector<QCPGraphData>::iterator it = tempData.begin();
const QVector<QCPGraphData>::iterator itEnd = tempData.end();
int i = 0;
while (it != itEnd)
{
it->key = keys[i];
it->value = values[i];
++it;
++i;
}
mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write
}
到了这里,关于QCustomPlot 绘制卡顿问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!