Qt Chart Series remove not shown data crashes Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Qt Chart Series remove not shown data crashes without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m trying to make a live plotting graph class in qt and the scrolling works. But when watching my program in Task Manager I recognized that the CPU and RAM usage increases by time (and data).

So I thought it would be a good style to use the remove function to delete data which is not shown anyway. Here’s my code:

void Live_Chart::UpdateY(float yValue)
this->yValue = yValue;
m_series->append(xValue, yValue);

if (xValue > m_axisX->max())
    // "Scroll" the data in the view

    // Remove the previous data we don't see
    qDebug() << "Removing " << m_axisX->min();

This method is called every 100 ms with a random number in between 0 and 10.

But always when reaching removing=52 the program crashes with this error msg:

ASSERT failure in QVector<T>::remove: "index out of range", file c:usersqtworkqtqtbaseincludeqtcore../../src/corelib/tools/qvector.h, line 483

And I really have no clue why 52. This number isn’t specified in any part of my program. The range of the x-axis is 50. On the create of the QLineSeries I am adding the point (0, 0).

EDIT: When using a m_axisX range of (0, 20) the program crashes when trying to delete point 22.

–> The program crashes when deleting a point whith x = x-range + 2 (Tested with other numbers too).


You are confusing the index of the data points in the vector m_series and their x value. When the data point with x = old_x_min goes out of the window you want to display, then that data point is at index 0 not at index old_x_min.





to remove the oldest data point, instead of some data point in the middle of the series.

We are here to answer your question about Qt Chart Series remove not shown data crashes - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji