I've got geap corruption detection in my code. An Error occure after destruction. The error is connected with QwtLegend and QwtPlotCurve pointers. I tried to use auto_ptr to have 100% certainty that memery is deallocated correctly, but even thought the error occures. I think that this is also connected with action where I pass these pointers to QwtPlot. Anyone can explain me how it should be correctly implemented? Below SSCCE code:
#include "plot.h"
Plot::Plot(QWidget *parent) :
QwtPlot(parent)
{
setUpPlot();
setUpCurves();
}
void Plot::setUpPlot()
{
legend = std::auto_ptr<QwtLegend>(new QwtLegend);
legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
this->insertLegend(legend.get(), QwtPlot::BottomLegend);
}
void Plot::setUpCurves()
{
aXCurve = new QwtPlotCurve("Acceleration in X axis");
aXCurve->attach(this);
replot();
}
Plot::~Plot()
{
aXCurve->detach();
delete aXCurve;
aXCurve = NULL;
}
#ifndef PLOT_H
#define PLOT_H
#include <qwt_plot.h>
#include <qwt_legend.h>
#include <qwt_plot_curve.h>
class Plot : public QwtPlot
{
Q_OBJECT
public:
explicit Plot(QWidget *parent = 0);
~Plot();
private:
void setUpPlot();
void setUpCurves();
std::auto_ptr<QwtLegend> legend;
QwtPlotCurve *aXCurve;
};
#endif // PLOT_H