Search code examples
qtqt-creator

Qt Creator no longer displays console output in Application Output window after Windows 10 1809 update


I'm running an application in debug with Qt 5.2.1 and Qt Creator 4.5.0. For many months this has been fine, and the console output is shown in the Application Output window. I applied the 1809 update to Windows this morning, and now I only see exception details in the output window, nothing else.

Interestingly, when I "Run in Terminal" the output is shown in the command window. It's also shown if I "Run" (ctrl-R) the application. It also seems to be OK when I run the tests for an application with a later version of the Qt framework (5.12.1, in my case).

Has anyone else experienced this? I'm not even sure where to start with fixing the problem.

EDIT: More information. I looked at the Qt 5.2.1 sources and saw that the qDefaultMessageHandler doesn't output the message if a console window is attached to the process (as you'd expect, for example if you selected the "Run in Terminal option"). If I call FreeConsole() at the beginning of my application, then the output appears as it used to in the Application Output window. This suggests that the update to Windows has caused a console window to be allocated to the debug process.


Solution

  • For those of you that are interested, I worked around the problem by conditionally calling FreeConsole() at the beginning of the program, like this:

    #ifdef Q_OS_WIN
    #include <Windows.h>
    #endif
    
    ...
    
    #ifdef Q_OS_WIN
    #if QT_VERSION <= QT_VERSION_CHECK(5, 2, 1)
        // Since the Windows 10 1809 update was pushed, the debug process has a
        // hidden console window allocated to it. This prevents the application output
        // reaching the console window in Qt 5.2.1 (see qlogging.cpp in the qt source for
        // reasons why). This detaches that console window, meaning the output is shown in the
        // application output window again. However, if "Run in terminal" is selected in the
        // Run options then the output will still be shown in the Application Output window.
        FreeConsole();
    #endif
    #endif