Results 1 to 13 of 13

Thread: Memory Error on Deleting a widget

  1. #1
    Join Date
    Nov 2011
    Location
    Germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Memory Error on Deleting a widget

    Quote Originally Posted by Harm View Post
    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.

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Memory Error on Deleting a widget

    Quote Originally Posted by Harm View Post
    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

  4. #4
    Join Date
    Nov 2011
    Location
    Germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: Memory Error on Deleting a widget

    Hi Uwe,

    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:
    Qt Designer.jpg

    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

  5. #5
    Join Date
    Nov 2011
    Location
    Germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: Memory Error on Deleting a widget

    Quote Originally Posted by Harm View Post
    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.

    Qt Code:
    1. Q_GraphView::Q_GraphView(QWidget *parent)
    2. : QDialog(parent)
    3. {
    4. ui.setupUi(this);
    5.  
    6. QVector<QPointF> averageData;
    7. averageData.push_back( QPointF(0,0) );
    8. averageData.push_back( QPointF(1,1) );
    9. averageData.push_back( QPointF(2,5) );
    10. QwtPlotCurve *curve = new QwtPlotCurve( "Test" );
    11. curve->setRenderHint( QwtPlotItem::RenderAntialiased );
    12.  
    13. QwtSymbol *symbol = new QwtSymbol( QwtSymbol::XCross );
    14. symbol->setSize( 4 );
    15. symbol->setPen( QPen( QColor( "red" ) ) );
    16. curve->setSymbol( symbol );
    17.  
    18. curve->setSamples( averageData );
    19. curve->attach( ui.PlotArea );
    To copy to clipboard, switch view to plain text mode 

    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.

  6. #6
    Join Date
    Nov 2011
    Location
    Germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory Error on Deleting a widget

    Ok, additional, what I found out:
    I added
    Qt Code:
    1. ui.PlotArea->setAutoDelete( false );
    To copy to clipboard, switch view to plain text mode 
    in the constructor to avoid deleting the pointers, but the problem walks up the line, a screen from my callstack:
    Callstack.jpg

    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. :-(

  7. #7
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

  8. #8
    Join Date
    Nov 2011
    Location
    Germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory Error on Deleting a widget

    Quote Originally Posted by Spitfire View Post
    Try the same without using qt designer.
    No Problem, tried with:
    Qt Code:
    1. Q_GraphView::Q_GraphView(QWidget *parent)
    2. : QDialog(parent)
    3. {
    4. ui.setupUi(this);
    5.  
    6. m_Plot = new QwtPlot( this );
    7. m_Plot->setAutoDelete( false );
    8.  
    9. QVector<QPointF> averageData;
    10. averageData.push_back( QPointF(0,0) );
    11. averageData.push_back( QPointF(1,1) );
    12. averageData.push_back( QPointF(2,5) );
    13. QwtPlotCurve *curve = new QwtPlotCurve( "Test" );
    14. curve->setRenderHint( QwtPlotItem::RenderAntialiased );
    15.  
    16. QwtSymbol *symbol = new QwtSymbol( QwtSymbol::XCross );
    17. symbol->setSize( 4 );
    18. symbol->setPen( QPen( QColor( "red" ) ) );
    19. curve->setSymbol( symbol );
    20.  
    21. curve->setSamples( averageData );
    22. curve->attach( m_Plot );
    23. }
    To copy to clipboard, switch view to plain text mode 

    So I tried some tricks with the lib :-)

    Ahhh and of course, I defined a QwtPlot pointer in the header file.

  9. #9
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory Error on Deleting a widget

    which objects do you delete manually in the destructor (or elsewhere)?

  10. #10
    Join Date
    Nov 2011
    Location
    Germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?
    Last edited by Harm; 24th November 2011 at 21:44.

  11. #11
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Memory Error on Deleting a widget

    The problem is in

    1. your code
    2. your build environment

    When you post the complete code of a crashing demo we could check at least 1).

    Uwe

  12. #12
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Memory Error on Deleting a widget

    Quote Originally Posted by Harm View Post
    Qt Code:
    1. ui.setupUi(this);
    To copy to clipboard, switch view to plain text mode 
    I still think it's the designer which you're using to create the dialog.

    Qt Code:
    1. #include "mydialog.h"
    2.  
    3. #include <QVBoxLayout>
    4.  
    5. #include <qwt_plot.h>
    6.  
    7. MyDialog::MyDialog(QWidget *parent) :
    8. QDialog(parent)
    9. {
    10. QVBoxLayout* lay = new QVBoxLayout();
    11.  
    12. QwtPlot* plot = new QwtPlot(this);
    13. lay->addWidget( plot );
    14.  
    15. this->setLayout(lay);
    16. }
    To copy to clipboard, switch view to plain text mode 
    Works perfectly fine here.

  13. #13
    Join Date
    Nov 2011
    Location
    Germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

Similar Threads

  1. Deleting characters in QLineEdit widget
    By Santiago in forum Newbie
    Replies: 2
    Last Post: 11th November 2011, 14:18
  2. Deleting children of a widget
    By ComServant in forum Newbie
    Replies: 5
    Last Post: 7th October 2011, 00:09
  3. Replies: 4
    Last Post: 16th April 2011, 10:19
  4. deleting a widget
    By john_god in forum General Programming
    Replies: 1
    Last Post: 30th December 2010, 09:36
  5. creating/deleting Objects // memory leaks
    By janus in forum Qt Programming
    Replies: 4
    Last Post: 27th March 2008, 18:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.