Results 1 to 14 of 14

Thread: will Qt delete all dynamic data?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Join Date
    Jan 2006
    Posts
    40
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: will Qt delete all dynamic data?

    Try the following:
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QtGui>
    5.  
    6. class Widget : public QWidget
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. Widget(QWidget *parent = 0) : QWidget(parent) {}
    12.  
    13. ~Widget()
    14. {
    15. qDebug() << "I AM IN DESTRUCTOR OF WIDGET!";
    16. }
    17. };
    18.  
    19. #endif // WIDGET_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "widget.h"
    2.  
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. QMainWindow mainWin;
    9. Widget *widget = new Widget(&mainWin);
    10. mainWin.show();
    11.  
    12. return app.exec();
    13. };
    To copy to clipboard, switch view to plain text mode 

    See that whilst in the mainWindow I've not set up a parent when the app closes it gets deleted (because it's on the stack) and then the widget which is a child of mainWindow is deleted. (Or at least the destructor is called!)
    Last edited by graeme; 31st May 2010 at 07:59.

Similar Threads

  1. delete first row of data from .csv file?
    By babymonsta in forum Qt Programming
    Replies: 3
    Last Post: 20th May 2010, 03:39
  2. Replies: 4
    Last Post: 16th January 2010, 10:08
  3. Replies: 4
    Last Post: 4th September 2009, 08:33
  4. Replies: 4
    Last Post: 19th February 2009, 11:10
  5. Dynamic Data Display with OpenGL
    By showhand in forum Qt Programming
    Replies: 3
    Last Post: 14th March 2006, 01: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.