PDA

View Full Version : Qwt - corrupts memory when destroy qwtplot



deepet
20th February 2013, 15:45
Hi.

I have a problem in Qwt 6.0, when i make delete of an qwtplot object. For example:


#include <QObject>

class QwtPlot;
class QwtPlotCurve;

class myClass : public QObject {
public:
myClass(QWidgte *parent, double *xData, double *xData, int TDataSize);
~myClass();

private:
QwtPlot *plot;
QwtPlotCurve *curve;
}

myClass:myClass(QWidgte *parent_, double *xData, double *xData, int TDataSize) {
plot = new QwtPlot(parent_);

curve = new QwtPlotCurve();
curve->attach(plot);
curve->setStyle(QwtPlotCurve::NoCurve);
curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::darkMagenta), QPen(Qt::darkMagenta), QSize(6, 6)));
curve->setPen(QPen(QColor(0, 0, 255)));
curve->setRawSamples(xDados, yDados, TDataSize-1);
}

myClass:~myClass() {
curve->attach(NULL);
delete curve;
delete plot; // with this crash
}

If I don't do
delete plot; and only do delete the myClass object I don't have problem, but I think that this isn't the correct way for doing this.
Other thing is that in the old version of Qwt, Qwt 5; I did do
delete plot; without any problem.
In Visual Studio 2010 the error message is: "Unhandled exception at 0x775415de in myApp.exe: 0xC0000005: Access violation."

Someone can help me?

Thanks.

jesse_mark
20th February 2013, 16:13
I'm a noob as you so ill try and guess with you :P,
you are setting a parent to the plot, so either remove the parent when you create your plot or don't delete it your self.

lanz
21st February 2013, 06:18
There's good(as always with Qt :D) piece of docs:
http://qt-project.org/doc/qt-4.8/objecttrees.html