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

Andreas Pakulat apaku at gmx.de
Fri Jun 26 21:09:59 CEST 2009


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

-- 
You work very hard.  Don't try to think as well.



More information about the Qt-interest-old mailing list