PDA

View Full Version : Is it possible to prevent closure of the standard out terminal from killing our app?



philw
3rd May 2014, 18:15
We have a large Qt 4.8.5 Windows desktop C++ / QWidget application which prints some information to standard out. That shows a terminal window. Unfortunately, clicking the Close-Window ("X") title-bar button on that terminal window ABORTS the entire application!

We need to prevent that, EITHER BY preventing the terminal window closure -- OR at least by preventing the effect of that closure killing our application.

Of course, in Qt, clicking that Close-Window ("X") button in a QWidget’s window can be ignored by intercepting and calling ignore() on the QCloseEvent. I don’t imagine that is relevant to the terminal window’s close-window button.

Is there some Windows event handler (or something) we can define to consume that event? (or something) to prevent that window from closing, or at least prevent the application from exiting when that terminal window is closed?

Or, as a last ditch can we force a message like "CLOSING THIS WINDOW WILL ABORT (THE APPLICATION) !!!" onto the standard-out terminal window's title bar? (But what we really want is the right solution).

(We’re using Visual Studio 2010, mostly Windows 7).
Thank you in advance. – Phil

Wysodava
3rd May 2014, 23:06
could you just get away with not having a console (http://qt-project.org/doc/qt-4.8/qmake-variable-reference.html#config) application? In other words, change the project file to remove console.

CONFIG -= console
CONFIG += windows
if you need the output, you could redirect with ios::rdbuf (http://www.cplusplus.com/reference/ios/ios/rdbuf/)