Hello,
I'm trying to make a plot which updates dynamically like in cpuplot example of QWT.
Everything goes fine excepted that when I'm trying to set new datas with setRawSamples in Qt's timer I experiment read violation access. Here is my sample class :
#include "StdAfx.h"
QTimeStepView
::QTimeStepView(QWidget *parent
) , count(0.0)
{
{
m_x.push_back(count);
m_y.push_back(count);
count +=1;
m_x.push_back(count);
m_y.push_back(count);
count +=1;
m_x.push_back(count);
m_y.push_back(count);
count +=1;
}
this->setAutoReplot(false);
// Show a title
setTitle( "This is an Example" );
// Show the axes
setAxisTitle( xBottom, "Time" );
setAxisTitle( yLeft, "Timestep" );
m_timestep->attach(this);
replot();
m_timestep->setRawSamples(&m_x[0], &m_y[0], m_x.size());
replot();
{
m_x.push_back(count);
m_y.push_back(count);
count +=1;
}
m_timestep->setRawSamples(&m_x[0], &m_y[0], m_x.size());
replot();
(void)startTimer(1000);
}
QTimeStepView::~QTimeStepView()
{
}
{
m_x.push_back(count);
m_y.push_back(count);
count +=1;
m_timestep->setRawSamples(&m_x[0], &m_y[0], m_x.size()); //Here happens the error
replot();
}
#include "StdAfx.h"
QTimeStepView::QTimeStepView(QWidget *parent)
: QwtPlot(parent)
, count(0.0)
{
{
m_x.push_back(count);
m_y.push_back(count);
count +=1;
m_x.push_back(count);
m_y.push_back(count);
count +=1;
m_x.push_back(count);
m_y.push_back(count);
count +=1;
}
this->setAutoReplot(false);
// Show a title
setTitle( "This is an Example" );
// Show the axes
setAxisTitle( xBottom, "Time" );
setAxisTitle( yLeft, "Timestep" );
QwtPlotCurve *m_timestep = new QwtPlotCurve("timestep");
m_timestep->attach(this);
replot();
m_timestep->setRawSamples(&m_x[0], &m_y[0], m_x.size());
replot();
{
m_x.push_back(count);
m_y.push_back(count);
count +=1;
}
m_timestep->setRawSamples(&m_x[0], &m_y[0], m_x.size());
replot();
(void)startTimer(1000);
}
QTimeStepView::~QTimeStepView()
{
}
void QTimeStepView::timerEvent(QTimerEvent* event)
{
m_x.push_back(count);
m_y.push_back(count);
count +=1;
m_timestep->setRawSamples(&m_x[0], &m_y[0], m_x.size()); //Here happens the error
replot();
}
To copy to clipboard, switch view to plain text mode
Severals setRawSamples goes fine in constructor but if I try to make it in the timer it doesn't work.
Bookmarks