PDA

View Full Version : How to close two main windows at a time



soumya
2nd February 2010, 11:09
Hi All,

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

aamer4yu
2nd February 2010, 11:18
Can you call QWidget::close :rolleyes:

soumya
2nd February 2010, 11:21
if i do that only one form will get closed and the other will be open i need to close both the forms together

navi1084
2nd February 2010, 11:43
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.

soumya
2nd February 2010, 11:48
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.

navi1084
2nd February 2010, 12:12
use installEventFilter() from parent class and in eventFilter() check for the Keypressed event and ESCAPE Character. depending on that close everything

aamer4yu
2nd February 2010, 13:20
Are your forms custom widgets ?
If yes, you can override closeEvent of your widget and call qApp->quit().

spud
4th February 2010, 17:12
Or yet another suggestion:


QWidget *a, *b;
...
a->setAttribute(Qt::WA_DeleteOnClose);
b->setAttribute(Qt::WA_DeleteOnClose);
connect(a, SIGNAL(destroyed()), b, SLOT(deleteLater()));
connect(b, SIGNAL(destroyed()), a, SLOT(deleteLater()));