You will probably need to do something like the following:

In main(), call QApplication::setQuitOnLastWindowClosed() with the value false before you show the mainWindow. This is to prevent what happens in the signal handler (see below) from causing the app to quit too soon.

In your signal handler, call QApplication::closeAllWindows() first, using the global qApp pointer.
Next, display your QMessageBox.
When the user closes the message box, call QApplication::quit() and then exit the handler.

You might also need to add a call to QApplication::quit() after app.exec() in main, but probably not since main() exits at that point anyway.

Another option would be to define your mainwindow pointer as a global variable in main.cpp so you can get to it from your signal handler. The all you have to do is call mainwindow->hide() from inside the handler before you display your message box. You should probably also call QApplication::quit() after the message box is closed so Qt can have a chance to clean up instead of just crashing out.