[Qt-interest] close app before exec()

Martin Gebert martin.gebert at alpha-bit.de
Wed Jul 1 11:19:23 CEST 2009


> I have QMainWindow application. In the QMainWindow constructor I check
> for conditions and if they are not met I want to exit from the
> application. The close(), QApplication::exit(), and so on doesn't
> work, because they are before application.exec().

   1. You could use exit() (from libc, global namespace) immediately in
      your constructor if the conditions aren't met. I'd consider is as
      inelegant and problematic.
   2. Set a flag (boolean member) in your constructor on success of the
      initialization, reimplement QMainWindow::exec() for your main
      window class and return with the appropriate return code if the
      initialization failed.

Martin



More information about the Qt-interest-old mailing list