I draw a total of 64 curves in qml under the windows system. After initializing the canvas, I call adddata to fill in the data, and save the data points for about 5 minutes. For data that exceeds 5 minutes,
I call graph(ch)->data()->removeBefore() clears it. Previously, the timer was used to replot every 50 milliseconds. Now it is filled with data points of the specified length. However, there will be crashes
from time to time, and they are all in replot()/toPainter()->draw()->getLines()->getVisibleDataBounds(), The address pointed to by begin/end has been released.
I tried to lock in replot()/toPainter(), but the drawing speed dropped seriously, which caused a large backlog of data in my cache queue, and the curve continued to be drawn long time after stopping data collection.
void MWaveView::addSeriesData(int ch, double key, double value) { if ((ch < 0) || (ch >= m_channelMax)) return; if (checkChannelIsPlot(ch)) { QCPGraph* pGraph = graph(ch); if (!pGraph) return; pGraph->addData(key, value); } } void MWaveView::setChannelMaxXCache(int ch, double position, int length) { if ((ch < 0) || (ch >= m_channelMax)) return; if (checkChannelIsPlot(ch)) { QCPGraph* pGraph = graph(ch); if (!pGraph) return; if (pGraph->data()->size() > length) { pGraph->data()->removeBefore(pGraph->data()->at(pGraph->data()->size() - length)->key); for (int i = 0; i < TRACER_NUM_MAX; i++) { if (m_tracer[ch] + i) { if ((m_tracer[ch] + i)->graphKey() < (position - length)) { if (m_tracerLabel[ch] + i) (m_tracerLabel[ch] + i)->setVisible(false); (m_tracer[ch] + i)->setVisible(false); } } } } } } void MWaveView::updateShowSlots() { try { replot(QCustomPlot::rpQueuedReplot); } catch (...) { LOGGERS_ERROR << "replot fialed"; } } void CustomPlotItem::paint(QPainter* painter) { if (!painter->isActive()) return; if (!m_pWave) return; QPixmap picture(boundingRect().size().toSize()); QCPPainter qcpPainter(&picture); m_pWave->toPainter(&qcpPainter); painter->drawPixmap(QPoint(), picture); }