Results 1 to 14 of 14

Thread: will Qt delete all dynamic data?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: will Qt delete all dynamic data?

    in main create the widget on the stack, then it will be deleted when you leave the scope. Since Qt uses pimpl the main part of the object is allocated dynamically. but if you want to create your main window on the heap use:
    Qt Code:
    1. int returnValue = app.exec();
    2. delete widget;
    3. return returnValue;
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to Lykurg for this useful post:

    somename (31st May 2010)

  3. #2
    Join Date
    May 2010
    Posts
    39
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: will Qt delete all dynamic data?

    Ok, and please, give me some small utility, that can show to me memory leaks..(for windows)

  4. #3
    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.

  5. #4
    Join Date
    May 2010
    Posts
    39
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: will Qt delete all dynamic data?

    Ok, and one more question.
    I have mainWidget, that contain several other widget (window),
    and when I do following code, on my mainWidget I see other widget... I don't want that it show on mainWidget..


    code Code:
    1. class MainWidget : public QMainWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. MainWidget()
    6. {
    7. myForm = new MyForm(this);
    8. }
    9.  
    10. private:
    11. MyForm *myForm;
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    How to do myForm as a child without showing on MainWidget?

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: will Qt delete all dynamic data?

    where do you want to show it?
    Inside your main window: use layouts.
    outside your main widnow: use QDialog as a base class for example. or set the modal widget attribute.

  7. The following user says thank you to Lykurg for this useful post:

    somename (31st May 2010)

  8. #6
    Join Date
    May 2010
    Posts
    39
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: will Qt delete all dynamic data?

    aa.. QDialog..
    Ok, thanks!

  9. #7
    Join Date
    May 2010
    Posts
    39
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: will Qt delete all dynamic data?

    hmm.. I have one problem.
    My app has one QMainWindow, and several other QWidget that can be show on QMainWindow(one at the time, and it is not QTabWidget!!).

    There are several situations:

    qt Code:
    1. class Widget : public QWidget
    2. {
    3. Widget(QWidget *parent) : QWidget(parent) {};
    4. }
    5. //In this situation, on my QMainWindow are showing several widget at the time
    6.  
    7.  
    8. class Widget : public QDialog
    9. {
    10. Widget(QWidget *parent) : QDialog(parent) {};
    11. }
    12. //In this situation, widget show as a dialog, on other window (not in QMainWindow)
    13.  
    14. class Widget : public QWidget
    15. {
    16. Widget() {};
    17. }
    18. //In this situation all works fine, only this widget are showing on QMainWindow at the time. But it brings memory leaks,
    19. // because this widget has no parent, and i need to delete it by it self..
    20.  
    21. //In my QMainWindow I do this:
    22. setCurrentWidget(widget)
    To copy to clipboard, switch view to plain text mode 
    Last edited by somename; 31st May 2010 at 19:03.

  10. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: will Qt delete all dynamic data?

    Have a look at QStackedWidget!

  11. The following user says thank you to Lykurg for this useful post:

    somename (1st June 2010)

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
  •  
Qt is a trademark of The Qt Company.