Results 1 to 8 of 8

Thread: How to close two main windows at a time

  1. #1
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default How to close two main windows at a time

    Hi All,

    I have two forms open i need to close both the forms together how this can be done any suggestions

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to close two main windows at a time

    Can you call QWidget::close

  3. #3
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to close two main windows at a time

    if i do that only one form will get closed and the other will be open i need to close both the forms together

  4. #4
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to close two main windows at a time

    Make 2nd one parent as first form and launch 2nd form as non-modal. Set the single closing slot where you are closing the parent form.

    Else you can use QPrecess.

  5. #5
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to close two main windows at a time

    I am closing the form using keypress event if i press escape key from keyboard one of my form will be closed but i need to close both the forms together.

  6. #6
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to close two main windows at a time

    use installEventFilter() from parent class and in eventFilter() check for the Keypressed event and ESCAPE Character. depending on that close everything

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to close two main windows at a time

    Are your forms custom widgets ?
    If yes, you can override closeEvent of your widget and call qApp->quit().

  8. #8
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to close two main windows at a time

    Or yet another suggestion:
    Qt Code:
    1. QWidget *a, *b;
    2. ...
    3. a->setAttribute(Qt::WA_DeleteOnClose);
    4. b->setAttribute(Qt::WA_DeleteOnClose);
    5. connect(a, SIGNAL(destroyed()), b, SLOT(deleteLater()));
    6. connect(b, SIGNAL(destroyed()), a, SLOT(deleteLater()));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Close All Windows
    By Tino in forum Qt Programming
    Replies: 4
    Last Post: 14th April 2010, 13:35
  2. Replies: 11
    Last Post: 11th August 2008, 09:14
  3. Why when I close QDialog my main application gets killed?
    By alex chpenst in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2008, 22:57
  4. Close all windows
    By nowire75 in forum Newbie
    Replies: 4
    Last Post: 30th October 2007, 12:28
  5. How to close all windows that were created in main()?
    By Mister_Crac in forum Qt Programming
    Replies: 6
    Last Post: 13th November 2006, 10:57

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.