[Qt-interest] Returning arbitrary value with QApplication::exit ()

Pascal Patry iscy at invalidip.com
Fri Jun 26 21:22:45 CEST 2009


On Friday 26 June 2009 15:09:59 Andreas Pakulat wrote:
> On 26.06.09 12:12:17, Diego Schulz wrote:
> > Hi all,
> >
> > I'm wondering if it's correct to return an arbitrary value with
> > qApp->exit(). It works as I expect, but I'm not sure if it's completely
> > correcto to do what I do.
> >
> > I'll try to explain a bit,
> >
> > Suppose a main.cpp like this
> >
> >
> > #include <QtGui/QApplication>
> > #include "mainwindow.h"
> > #include "common.h"
> >
> > int main(int argc, char *argv[])
> > {
> >    int retcode=0;
> >
> >    do {
> >     QApplication a(argc, argv);
> >     MainWindow w;
> >     retcode = a.exec();
> >
> >    } while (retcode == RESTART_APPLICATION);
> >
> >   return retcode;
> > }
> >
> >
> > RESTART_APPLICATION is defined in common.h  as
> >
> >    #define RESTART_APPLICATION 333
> >
> > 333 is whatever, an arbitrary number.
> >
> > In a few circumstances, I want the application to be restarted (eg
> > database connection lost, etc), so I call
>
> I don't think its safe to re-create QApplication, AFAIK this can lead to
> subtle hard-to-track bugs later on.
>
> Andreas

I don't want to say that this kind of design is wrong, neither that you are, 
but I think that developing a software thinking that a particular class cannot 
be instantiated again once destroyed is a mistake.




More information about the Qt-interest-old mailing list