Results 1 to 5 of 5

Thread: Using child Widget Signal to close Parent Widget

  1. #1
    Join Date
    Jul 2009
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Using child Widget Signal to close Parent Widget

    Hello, All;

    I'm a Qt newbie trying to figure out how to use a signal on a child Widget to trigger a slot on a parent Widget. Basically, I'm trying to modify some existing code so that a button several levels down from the top-level Widget can close the entire window. Hopefully I'm explaining myself clearly and am open to any suggestions on how to tackle this. Thanks in advance...

    Allan

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using child Widget Signal to close Parent Widget

    there are several solutions

    but all of them require that you have access to pointers of both classes(button and mainwindow),

    you if you are working in button class
    Qt Code:
    1. //suppose your main window is two level above parent
    2. connect(this,SIGNAL(clicked()),this->parent()->parent(),SLOT(slot()));
    To copy to clipboard, switch view to plain text mode 

    if your are woking in mainwindow class... then somehow get the pointer to button(usually button is directly a memeber of your mainwindow class)
    Qt Code:
    1. connect(getButton(), SIGNAL(clicked()),this,SLOT(slot()));
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to nish for this useful post:

    bizmopeen (15th July 2009)

  4. #3
    Join Date
    Jul 2009
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Using child Widget Signal to close Parent Widget

    Quote Originally Posted by MrDeath View Post
    there are several solutions

    but all of them require that you have access to pointers of both classes(button and mainwindow),

    you if you are working in button class
    Qt Code:
    1. //suppose your main window is two level above parent
    2. connect(this,SIGNAL(clicked()),this->parent()->parent(),SLOT(slot()));
    To copy to clipboard, switch view to plain text mode 

    if your are woking in mainwindow class... then somehow get the pointer to button(usually button is directly a memeber of your mainwindow class)
    Qt Code:
    1. connect(getButton(), SIGNAL(clicked()),this,SLOT(slot()));
    To copy to clipboard, switch view to plain text mode 
    Thanks, Mr. Death!

  5. #4
    Join Date
    Jul 2009
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Using child Widget Signal to close Parent Widget

    Bump. I am revisiting this issue and don't seem to be having any success. Can anyone provide an alternate scenario? I can compile my code, but nothing happens when I try to close the parent window, I'm afraid...

  6. #5
    Join Date
    Nov 2008
    Location
    Częstochowa/Poland
    Posts
    50
    Thanks
    2
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using child Widget Signal to close Parent Widget

    Does Your application output any warnings at runtime? You may have a typo in a connect that would result in signals not being connected to slots.
    Last edited by Grimlock; 3rd October 2009 at 08:46.

Similar Threads

  1. How to move child widget with parent widget?
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 15:23
  2. let parent widget grow with child widget?
    By BeS in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 11:17
  3. How to close parent window from child window?
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2008, 11:40
  4. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:00
  5. Referencing Parent Widget from Child
    By taylor34 in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2006, 15:13

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.