[Qt-interest] Returning arbitrary value with QApplication::exit()
Pascal Patry
iscy at invalidip.com
Fri Jun 26 19:47:28 CEST 2009
On Friday 26 June 2009 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
>
> qApp->exit(RESTART_APPLICATION);
>
>
> Is it correct to use exit() in this way?
yes, it is correct and you can safely use it...
> Is there something I should be aware if I want to do this?
yes, on some platforms (at least on unix) the exit code will get into a
logical 'and'. the returned value will be 'status' & 0377. So the exit codes
are possible between 0 and 255 inclusively. If you strictly use your constant
inside your own application, you don't have to bother with this.
More information about the Qt-interest-old
mailing list