| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 3 | |
Hello,
I've spent the day tidying up some old code by adding error message boxes.
Now my curiosity has been aroused about the calling of the class destructor
when an application ends.
Say I have a single class application: myClass.cpp, a main window and a
main.cpp file.
Say also that an error message box pops up because because of an error
condition and when I press quit the button the application ends as it
should. The code to close the application is exit(0). I have also tried
QApplication::exit(0) but that doesn't close the application or call the
destructor.
In the class destructor I have something like the following to see if the
destructor is actually called and it doesn't seem to be.
{
Delete object1;
Cout << "destructor called" << endl;
}
It's only a hobby and not a matter of life and death, I was just wondering
if exit() is the correct way to quit and if the destructor is bypassed by
doing so.
Regards,
Phil and Lorraine.
--
[ signature omitted ]
On Saturday 14 July 2007, Phil wrote: > Say also that an error message box pops up because because of an error > condition and when I press quit the button the application ends as it > should. The code to close the application is exit(0). I have also tried > QApplication::exit(0) but that doesn't close the application or call the > destructor. QApplication::quit() and exit(int) don't end the application immediately. They just tell the eventloop that it should end itself next time the program returns to it. On the other hand ::exit(int) ends the whole program immediately without giving anything the chance to clean up properly. Chose your poison... ;-) Konrad
Attachment:
Attachment:
pgp3XP1pM7kFp.pgp
Description: PGP signature
Message 3 in thread
> QApplication::quit() and exit(int) don't end the application immediately.
> They just tell the eventloop that it should end itself next time the
> program returns to it. On the other hand ::exit(int) ends the whole program
> immediately without giving anything the chance to clean up properly.
Not exactly, with atexit you can install your handler(s) that will be
called on application exit.
Martin Petricek
--
[ signature omitted ]