You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, January 11th 2005, 8:53pm

cleanup when destroyed()

If the user closes my parent mainwindow using the system menu (right hand cross), then all other forms that I had launched from this mainwindow (its the parent) dont vanish.
When I exit this way the destructor doesnt run so a qApp->quit() isnt useful in the destr. The signal destroyed() cant be used since its already destroyed so cant run some slot. How can I make all the windows go away and the app quit after doing some cleanup work?
Thanks,
sb

I also tried:

Source code

1
2
3
4
5
6
7
8
9
10
int main( int argc, char ** argv )
{
    QApplication a( argc, argv );
    Form1 w;

    w.show();
    a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
        a.connect(&w, SIGNAL( destroyed() ), &a, SLOT( quit() ) );
    return a.exec();
}
Thanks.

This post has been edited 1 times, last edit by "bonosa" (Jan 11th 2005, 8:59pm)


hatulflezet

Professional

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

2

Tuesday, January 11th 2005, 9:13pm

Try this:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
int main( int argc, char ** argv )
{
    QApplication a( argc, argv );
    Form1 w;
    a.setMainWindow(&w);
    w.show();
    a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    a.exec();
    //delete w; //oops, its not a pointer... :rolleyes:
    return 0;

}
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"

3

Tuesday, January 11th 2005, 9:45pm

Yes!!!!!!!!!
It works with the setMainWidget. Many many many thanks!
sb
Thanks.