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

Diego Schulz dschulz at gmail.com
Fri Jun 26 18:12:17 CEST 2009


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? Is there something I should
be aware if I want to do this?


Thanks in advance,

diego



More information about the Qt-interest-old mailing list