Hello.
I have a problem with my QwtPlot-derived class:
{
public:
~Plot2D();
private:
SpectrogramData *meshData; // public : QwtRasterData,
ColorMap *meshMap; // : public QwtColorMap
// These two classes use their respective default destructors. No memory allocation takes place inside these classes.
};
class Plot2D : public QwtPlot
{
public:
Plot2D(QWidget *parent);
~Plot2D();
private:
QwtPlotSpectrogram *meshGrid;
SpectrogramData *meshData; // public : QwtRasterData,
ColorMap *meshMap; // : public QwtColorMap
// These two classes use their respective default destructors. No memory allocation takes place inside these classes.
QwtScaleDraw *scaleDraw;
QwtScaleWidget *rightAxis;
};
To copy to clipboard, switch view to plain text mode
Its constructor and destructor are set to:
meshData(new SpectrogramData()),
meshMap(new ColorMap()),
{
meshGrid->attach(this);
meshGrid->setData(meshData);
meshGrid->setColorMap(meshMap);
rightAxis
= axisWidget
(QwtPlot::yRight);
rightAxis->setColorBarEnabled(true);
setAxisScaleDraw
(QwtPlot::yLeft,scaleDraw
);
}
Plot2D::~Plot2D()
{
delete scaleDraw;
delete meshMap;
delete meshData;
delete meshGrid;
}
Plot2D::Plot2D(QWidget *parent) :
QwtPlot(parent),
meshGrid(new QwtPlotSpectrogram()),
meshData(new SpectrogramData()),
meshMap(new ColorMap()),
scaleDraw(new QwtScaleDraw())
{
meshGrid->attach(this);
meshGrid->setData(meshData);
meshGrid->setColorMap(meshMap);
rightAxis = axisWidget(QwtPlot::yRight);
rightAxis->setColorBarEnabled(true);
enableAxis(QwtPlot::yRight);
setAxisScaleDraw(QwtPlot::yLeft,scaleDraw);
}
Plot2D::~Plot2D()
{
delete scaleDraw;
delete meshMap;
delete meshData;
delete meshGrid;
}
To copy to clipboard, switch view to plain text mode
My program halts and eventually throws an error if I simply run it and subsequently close it (upon deleting the Plot2D object). This simple procedure is completed successfully if I comment out the bracketed instructions on either constructor or destructor. I'm guessing that there is something wrong with my implementation of memory management here. What might be the problem?
Bookmarks