Results 1 to 4 of 4

Thread: Why doesn't my dialog window close when the mainwindow is closed?

  1. #1
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Why doesn't my dialog window close when the mainwindow is closed?

    Hi!

    I have a problem with a dialog window that doesn't close when I close the MainWindow. The dialog isn't modal, because I want a window at the side of my main window that I can display state of the progam.

    I've read about parents and childs and thought that a child is closed when it's parent is. So either I've got this wrong or I've failed making the dialog a child to the main window.

    Heres a shortened version of the code:


    This is the dialog class:
    Qt Code:
    1. class OutlinerEditor : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5.  
    6. public:
    7.  
    8. OutlinerEditor ( std::vector<Renderable*> *v,
    9. std::vector<Renderable*> *s,
    10. QWidget *parent ):
    11. QDialog ( parent )
    12. {
    13. setWindowTitle ( "Outliner" );
    14.  
    15. treeModel = new TreeModel ( cmps );
    16.  
    17. outliner = new Outliner ( sels, this );
    18. outliner->setModel ( treeModel );
    19. outliner->connectSelection ( );
    20.  
    21. hLayout = new QHBoxLayout ( this );
    22. hLayout->addWidget ( outliner );
    23.  
    24. hLayout->setMargin ( 1 );
    25. setContentsMargins ( 1, 1, 1, 1 );
    26.  
    27. // and connections and so forth...
    28.  
    29. }// OutlinerEditor(v*,v*,W*)
    30.  
    31. };// class OutlinerEditor
    To copy to clipboard, switch view to plain text mode 


    This is the MainWindow class:
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MainWindow::MainWindow ( ):
    7. {
    8. canvasFrame = new CanvasFrame;
    9.  
    10. /* This is where I build the dialog and connects it, the last argument is the
    11.   * pointer to the parent.
    12.   */
    13. OutlinerEditor *outlinerEditor = new OutlinerEditor ( NULL, NULL, this );
    14.  
    15. /* This is how I show the dialog as not modal */
    16. outlinerEditor->show ( );
    17.  
    18. }// MainWindow()
    19.  
    20. };// class MainWindow
    To copy to clipboard, switch view to plain text mode 


    thanks for reading
    pir

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Why doesn't my dialog window close when the mainwindow is closed?

    Try to set attribute Qt::WA_DeleteOnClose for the main window. This assures that the main window is deleted upon closing and so the dialog should be destructed also.
    J-P Nurmi

  3. The following 2 users say thank you to jpn for this useful post:

    alr1970 (20th October 2009), pir (23rd July 2006)

  4. #3
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Why doesn't my dialog window close when the mainwindow is closed?

    I thought that the MainWindow was set to this as default. Thanks, I will try that. It's good to know, but I solved the problem with implementing the closeEvent() and close down all dialogs there. I needed to save the state of the dialogs anyway...

    But is the parent child relation ok?
    Because I'm a bit unsure about how the destruction of the widgets work. Can't find it explained in detail on the homepage. According to what I've understaned , is the children automatically destructed when the parent is destructed. But what about orphins? Do I need to destroy them myself, or does Qt's main loop take care of this when I close down the Qt session?

    thanks
    pir

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why doesn't my dialog window close when the mainwindow is closed?

    Quote Originally Posted by pir
    Because I'm a bit unsure about how the destruction of the widgets work.
    If a QObject is destructed, it destroys all its children each of which in turn destroy all its children, etc.

    But what about orphins? Do I need to destroy them myself, or does Qt's main loop take care of this when I close down the Qt session?
    You have to destroy them yourself. Qt doesn't do anything *magic*, it's just a C++ library.

Similar Threads

  1. Replies: 1
    Last Post: 1st June 2006, 12:46
  2. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

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.