Memory Error on Deleting a widget
Hi together,
I´m quite confused, what´s wrong in my programm. I installed qwt 6.0.1 on qt 4.7.2. Had some smaller problems on the creator plugin, but so long no problem, I fixed this issue.
Now I create a new dialog, with a QTabWidget item and placed a QwtPlot in it.
So far no problem. Because I like the whole thing, I introduced the lib in my project.
Compiled as debug, fixed missing headers and library references (Ok, it´s the debug build, no problem, checked this also for qwtd.lib and dll).
But when I close the dialog again my VS stops with a memory corruption from QwtScaleDiv.
I´m quite helpless, tried to strip the whole down, erased the tabwidget and so on, but have no idea, what´s wrong with the system. I have no drawing, or something else, only a nude widget.
Any help is appreciated,
kind regards,
Thomas
Re: Memory Error on Deleting a widget
Quote:
Originally Posted by
Harm
I have no drawing, or something else, only a nude widget.
I don't know anything about the classes involded. But just a guess: maybe you should have something other than a nude widget... as the corruption happens when you close the dialog, it might be that a destructor assumes something to contain something -- and if it doesn't, things get messed up. But doing just a little drawing might fix things.
Re: Memory Error on Deleting a widget
Quote:
Originally Posted by
Harm
But when I close the dialog again my VS stops with a memory corruption from QwtScaleDiv.
Nobody can tell you what you are doing wrong without knowing any code, but my guess is, that you are passing some parameters from the stack, that should be from the heap.
Uwe
1 Attachment(s)
Re: Memory Error on Deleting a widget
Hi Uwe,
Quote:
Nobody can tell you what you are doing wrong without knowing any code, but my guess is, that you are passing some parameters from the stack, that should be from the heap.
I would be happy, if there would be some code which causes the error. I only have a small screen:
Attachment 7121
I just inserted the plot widget, start the application, open the dialog, close it via close button and get a crash. I will try to implement some data though. Propably the lib is only shy because of painting a blank diagram.
Kind regards
Thomas
Re: Memory Error on Deleting a widget
Quote:
Originally Posted by
Harm
I just inserted the plot widget, start the application, open the dialog, close it via close button and get a crash. I will try to implement some data though. Propably the lib is only shy because of painting a blank diagram.
Ok, drilled through the code a littlebit. I inserted some code in the constructor to have some data displayed.
Code:
Q_GraphView
::Q_GraphView(QWidget *parent
){
ui.setupUi(this);
QVector<QPointF> averageData;
averageData.
push_back( QPointF(0,
0) );
averageData.
push_back( QPointF(1,
1) );
averageData.
push_back( QPointF(2,
5) );
curve
->setRenderHint
( QwtPlotItem::RenderAntialiased );
symbol->setSize( 4 );
curve->setSymbol( symbol );
curve->setSamples( averageData );
curve->attach( ui.PlotArea );
What I found out is the following: the data displays well, so far all ok, but the programm crashs in the destructor of the qwtplot. I will hunt in the detachItems now, because it seems that my problem is buried somewhere in there.
1 Attachment(s)
Re: Memory Error on Deleting a widget
Ok, additional, what I found out:
I added
Code:
ui.PlotArea->setAutoDelete( false );
in the constructor to avoid deleting the pointers, but the problem walks up the line, a screen from my callstack:
Attachment 7122
There is an odd reason, where the plot believes it has to be deleted, but I can´t imagine why. Besides, I tried to code the plot as well, but the result is the same. :-(
Re: Memory Error on Deleting a widget
Try the same without using qt designer.
Just simple main window with plot set as a central widget.
Re: Memory Error on Deleting a widget
Quote:
Originally Posted by
Spitfire
Try the same without using qt designer.
No Problem, tried with:
Code:
Q_GraphView
::Q_GraphView(QWidget *parent
){
ui.setupUi(this);
m_Plot->setAutoDelete( false );
QVector<QPointF> averageData;
averageData.
push_back( QPointF(0,
0) );
averageData.
push_back( QPointF(1,
1) );
averageData.
push_back( QPointF(2,
5) );
curve
->setRenderHint
( QwtPlotItem::RenderAntialiased );
symbol->setSize( 4 );
curve->setSymbol( symbol );
curve->setSamples( averageData );
curve->attach( m_Plot );
}
So I tried some tricks with the lib :-)
Ahhh and of course, I defined a QwtPlot pointer in the header file.
Re: Memory Error on Deleting a widget
which objects do you delete manually in the destructor (or elsewhere)?
Re: Memory Error on Deleting a widget
None, I have only an empty destructor. I`m relying on the "Garbage Collector" of QT.
It looks like there is a point in QwtPlotDict where the plot is deleted and the widget wants to delete it afterwards...
BTW I checked with the examples, no problems with them. I suspect, it may be an issue with using plots in dialogs. Is anybody here, who can give a small example using a plot in a dialog?
Re: Memory Error on Deleting a widget
The problem is in
- your code
- your build environment
When you post the complete code of a crashing demo we could check at least 1).
Uwe
Re: Memory Error on Deleting a widget
Quote:
Originally Posted by
Harm
I still think it's the designer which you're using to create the dialog.
Code:
#include "mydialog.h"
#include <QVBoxLayout>
#include <qwt_plot.h>
MyDialog
::MyDialog(QWidget *parent
) :{
lay->addWidget( plot );
this->setLayout(lay);
}
Works perfectly fine here.
Re: Memory Error on Deleting a widget
Hi all,
I found my error. Investigating the error message from the library I got the, which led me to MSDN Explanation. So I checked my settings, Qwt is compiled with /MDd, whilst my programm is compiled with /MTd. This gives you the small difference, that I link static against CRT, and Qwt uses the dynamic CRT.
After creating a new DLL for my purpose and compile it with /MDd as well the programm returns no crash! Excellent! :)
I'm sorry, but I'm not able to compile my program with /MDd, because I use some other demanding libs which demand to be compiled in this manner. But gladfully the workaround helps me on my problem!
Thanks all for your hints!
Thomas