PDA

View Full Version : Using child Widget Signal to close Parent Widget



bizmopeen
15th July 2009, 02:09
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

nish
15th July 2009, 02:36
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

//suppose your main window is two level above parent
connect(this,SIGNAL(clicked()),this->parent()->parent(),SLOT(slot()));

if your are woking in mainwindow class... then somehow get the pointer to button(usually button is directly a memeber of your mainwindow class)

connect(getButton(), SIGNAL(clicked()),this,SLOT(slot()));

bizmopeen
15th July 2009, 03:05
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

//suppose your main window is two level above parent
connect(this,SIGNAL(clicked()),this->parent()->parent(),SLOT(slot()));

if your are woking in mainwindow class... then somehow get the pointer to button(usually button is directly a memeber of your mainwindow class)

connect(getButton(), SIGNAL(clicked()),this,SLOT(slot()));

Thanks, Mr. Death!

bizmopeen
2nd October 2009, 18:01
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...

Grimlock
3rd October 2009, 08:19
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.