From 7fab8eb56b9309734d1b34d3d935d6a4cf14ce6e Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 7 Jan 2014 14:43:22 +0100 Subject: Windows: Do not print test output to both stdout and system debug log Avoid piping the test output to both the Windows system debugger, and stdout. This fixes duplicate output in Qt Creator, which displays messages from both sources. [ChangeLog][QtTestLib] The (default) plain text logger on Windows now logs to either the system debug log (in case no console is open), or stdout, not both. Task-number: QTBUG-34630 Change-Id: I35fe9f4a50cc660d79fad7dffa6d19659b2102ae Reviewed-by: Thiago Macieira Reviewed-by: Friedemann Kleint --- src/corelib/global/qlogging.cpp | 2 +- src/testlib/qplaintestlogger.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index cc20891c76..5b7a674ddb 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -102,7 +102,7 @@ static inline bool hasStdErr() } # endif // !Q_OS_WINCE && !Q_OS_WINRT -bool qWinLogToStderr() +Q_CORE_EXPORT bool qWinLogToStderr() { # if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) static const bool result = hasStdErr(); diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index 77be0e423e..3f65dc0a6e 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -197,6 +197,10 @@ namespace QTest { } } +#if defined(Q_OS_WIN) +Q_CORE_EXPORT bool qWinLogToStderr(); // defined in qlogging.cpp +#endif + void QPlainTestLogger::outputMessage(const char *str) { #if defined(Q_OS_WINCE) @@ -209,7 +213,11 @@ void QPlainTestLogger::outputMessage(const char *str) } while (!strUtf16.isEmpty()); if (stream != stdout) #elif defined(Q_OS_WIN) - OutputDebugStringA(str); + // log to system log only if output is not redirected, and no console is attached + if (!qWinLogToStderr() && stream == stdout) { + OutputDebugStringA(str); + return; + } #elif defined(Q_OS_ANDROID) __android_log_write(ANDROID_LOG_INFO, "QTestLib", str); #endif -- cgit v1.2.3