On Wed, Sep 26, 2007 at 10:58:41PM +0200, Peter Kümmel wrote: > Abdelrazak Younes wrote: > >>Using ::exit often results (with Qt) in a crash because destructors > >>of static (Qt) objects are called in arbitrary order. > > > >Are you sure? AFAIK ::exit() will exit without any cleanup. > > #include <stdlib.h> > > struct A { > int* ptr; > A() : ptr(0) {} > ~A() { int i = *ptr; } > }; > > // comment out to avoid crash (msvc) > A a; > > int main() { > A b; > exit(1); > return 0; > } > > > > > >>The best solution > >>would be to leave Qt's event loop and to regulary return from app.exec(). > >> > >>Therefore, does it work to call QCoreApplication::exit instead of ::exit? > > > >I've tried and it doesn't work fine because then we exit normally. > > Wouldn't it be better to catch an exception in main: > > catch { > QCoreApplication::exit(1) > return 1; > } > > I only ask, because we had really strange cross-platform problems in the > past because of using exit
Right. ::exit() should not be used. Ever (except perhaps for very simple C programs, but even then there will usually some way to 'return' from main... Andre'