I have written a program mostly by copying the oscilloscope example

I am deleting the oldest item stored in the data series in a callback using the following code:

rwValues.lockForWrite();

boundingRect = QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid

const QVector<QPointF> values = m_Values;
m_vecValues.clear();
m_vecValues.reserve( values.size() );

int index = 1;

while ( index < values.size() - 1 )
append( values[index++] ); // in this function I add values to m_Values

rwValues.unlock();

Now QwtDataSeries::sample is called by

__GI_raise 0x00007f47f458de97
__GI_abort 0x00007f47f458f801
QMessageLogger::fatal(char const*, ...) const 0x00007f47f5312b5e
qt_assert_x(char const*, char const*, char const*, int) 0x00007f47f530e391
QVector<QPointF>:perator[] qvector.h:434
SignalCurveData::sample SignalCurveData.cpp:88
QwtPointMapper::toPolygonF(QwtScaleMap const&, QwtScaleMap const&, QwtSeriesData<QPointF> const*, int, int) const 0x00007f47f6479292
QwtPlotCurve::drawLines(QPainter*, QwtScaleMap const&, QwtScaleMap const&, QRectF const&, int, int) const 0x00007f47f6448486
QwtPlotCurve::drawSeries(QPainter*, QwtScaleMap const&, QwtScaleMap const&, QRectF const&, int, int) const 0x00007f47f6446e53
QwtPlotSeriesItem::draw(QPainter*, QwtScaleMap const&, QwtScaleMap const&, QRectF const&) const 0x00007f47f6463cef
QwtPlot::drawItems(QPainter*, QRectF const&, QwtScaleMap const*) const 0x00007f47f64401f0
QwtPlot::drawCanvas(QPainter*) 0x00007f47f6440006
QwtPlotCanvas::drawCanvas(QPainter*, bool) 0x00007f47f646ad3a
QwtPlotCanvas:aintEvent(QPaintEvent*) 0x00007f47f646cc78
QWidget::event(QEvent*) 0x00007f47f6aa5a58
QFrame::event(QEvent*) 0x00007f47f6b81dee
QApplicationPrivate::notify_helper(QObject*, QEvent*) 0x00007f47f6a674bc
QApplication::notify(QObject*, QEvent*) 0x00007f47f6a6e8e7
QCoreApplication::notifyInternal2(QObject*, QEvent*) 0x00007f47f54f7eb8
QWidgetPrivate::sendPaintEvent(QRegion const&) 0x00007f47f6a9ef0a
QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) 0x00007f47f6a9f519
<unknown> 0x00007f47f6a76a5f
<unknown> 0x00007f47f6a76d20
QWidgetPrivate::syncBackingStore() 0x00007f47f6a8f3af
QWidget::event(QEvent*) 0x00007f47f6aa5b60
QMainWindow::event(QEvent*) 0x00007f47f6b8fa4b
QApplicationPrivate::notify_helper(QObject*, QEvent*) 0x00007f47f6a674bc
QApplication::notify(QObject*, QEvent*) 0x00007f47f6a6e8e7
QCoreApplication::notifyInternal2(QObject*, QEvent*) 0x00007f47f54f7eb8
QCoreApplicationPrivate::sendPostedEvents(QObject* , int, QThreadData*) 0x00007f47f54fa54b
<unknown> 0x00007f47f554aad3
g_main_context_dispatch 0x00007f47f0e81287
<unknown> 0x00007f47f0e814c0
g_main_context_iteration 0x00007f47f0e8154c
QEventDispatcherGlib:rocessEvents(QFlags<QEventLoop::ProcessEventsFlag> ) 0x00007f47f554a11f
QEventLoop::exec(QFlags<QEventLoop::ProcessEventsF lag>) 0x00007f47f54f64aa
QCoreApplication::exec() 0x00007f47f54fed34
main main.cpp:90
__libc_start_main 0x00007f47f4570b97
_start 0x000055edb74a0a4a

Now naturally when it is called this way they don't lock the mutexes protecting the values QVector and so the code:

return m_Values[i];

in sample(size_t i) fails with an exceptio. I have reviewed the oscilloscope example many times, the implementation is same then why am I facing this error.

I am using Qt 5.9.1 and Qwt 6.1.3

Can someone please help with this?