Results 1 to 6 of 6

Thread: How to close parent window from child window?

  1. #1
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question How to close parent window from child window?

    I have the following problem:

    I have a Qt Dialog from which i open another child Qt Dialog. Now if user clicks on some button on the child Dialog and some error occurs, i want to close the child window as well as the parent window. I am able to close the child window using
    Qt Code:
    1. this->close ()
    To copy to clipboard, switch view to plain text mode 
    Since at the time user clicks on the button, the control is in the child window so i can close the child window, but how can i close the parent window?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to close parent window from child window?

    if you need that after closing a parent widget, a child widget is closed too, then you need add parent into ctor of a child widget.

  3. #3
    Join Date
    Sep 2008
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to close parent window from child window?

    Can't you connect a signal on destruction of the child window to the close() slot in the parent? That is, something like:

    Qt Code:
    1. connect(this,SIGNAL(destroyed()),this->parent(),SLOT(close());
    To copy to clipboard, switch view to plain text mode 

    assuming, of course that the child window is a genuine Qt child object (its constructor has been passed the parent window.)
    Last edited by daggilli; 14th October 2008 at 04:09.

  4. The following user says thank you to daggilli for this useful post:

    Richard H (15th March 2017)

  5. #4
    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 parent window from child window?

    May be you can call qApp->quit() when some error occurs.
    QCoreApplication::quit

  6. #5
    Join Date
    Jul 2008
    Location
    Mumbai, India
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to close parent window from child window?

    I think that if you emit a user defined signal from the child and catch it in the parent, the you can close the parent. However, due to the parent - child relationship, the child shall also be closed when the parent closes.

  7. #6
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Cool Re: How to close parent window from child window?

    Quote Originally Posted by daggilli View Post
    Can't you connect a signal on destruction of the child window to the close() slot in the parent? That is, something like:

    Qt Code:
    1. connect(this,SIGNAL(destroyed()),this->parent(),SLOT(close());
    To copy to clipboard, switch view to plain text mode 

    assuming, of course that the child window is a genuine Qt child object (its constructor has been passed the parent window.)
    This doesn't work. this->parent () returns NULL in my case.

    Quote Originally Posted by aamer4yu View Post
    May be you can call qApp->quit() when some error occurs.
    QCoreApplication::quit
    I don't want to close the entire application so i can't use qApp->quit().

    Quote Originally Posted by ankit17.ag View Post
    I think that if you emit a user defined signal from the child and catch it in the parent, the you can close the parent. However, due to the parent - child relationship, the child shall also be closed when the parent closes.
    Yes, this is one of the ways of doing the job. This is specially useful if one wants to close the parent window in response to some event in the child window.

    I was able to close the parent window after the child window is closed. I referred this thread:

    http://www.qtcentre.org/forum/f-qt-p...sed-14009.html

    So basically, once the child dialog closes, i call this->close () in the parent function and parent window is closed too.

    Thanks to everyone for replying to this thread

Similar Threads

  1. connecting child to parent window...
    By sumit in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2008, 21:28
  2. Set a window as child at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2007, 09:30
  3. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  4. Replies: 3
    Last Post: 23rd July 2006, 18:02
  5. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:00

Tags for this Thread

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.