From d9a1c2dff85635076ecaee3507427d750846c85c Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 2 Apr 2012 13:48:06 +0200 Subject: Logging: Change arguments of message handler to avoid conversions Introduce a new QtMessageHandler that takes QString instead of char *: This avoids converting to local8bit , only to convert it back to utf16 for Windows. The old QMessageHandler is kept for a transition period, but will be removed before Qt 5.0. Also fix qEmergencyOut (that is called in OOM situations) to not rely on the default message handler. Change-Id: Iee0ce5838f97175c98788b847964273dd22d4a37 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcoreapplication_win.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/corelib/kernel/qcoreapplication_win.cpp') diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp index 7cc1f0e286..5649a8dd76 100644 --- a/src/corelib/kernel/qcoreapplication_win.cpp +++ b/src/corelib/kernel/qcoreapplication_win.cpp @@ -141,29 +141,28 @@ public: }; // defined in qlogging.cpp -extern Q_CORE_EXPORT QByteArray qMessageFormatString(QtMsgType type, - const QMessageLogContext &context, - const char *str); +extern Q_CORE_EXPORT QString qMessageFormatString(QtMsgType type, + const QMessageLogContext &context, + const QString &str); -Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogContext &context, const char *str) +Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogContext &context, const QString &str) { // cannot use QMutex here, because qWarning()s in the QMutex // implementation may cause this function to recurse static QWinMsgHandlerCriticalSection staticCriticalSection; - QByteArray message = qMessageFormatString(t, context, str); - QString s(QString::fromLocal8Bit(message)); + QString message = qMessageFormatString(t, context, str); // OutputDebugString is not threadsafe. staticCriticalSection.lock(); - OutputDebugString((wchar_t*)s.utf16()); + OutputDebugString((wchar_t*)message.utf16()); staticCriticalSection.unlock(); } Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char *str) { QMessageLogContext emptyContext; - qWinMessageHandler(t, emptyContext, str); + qWinMessageHandler(t, emptyContext, QString::fromLocal8Bit(str)); } /***************************************************************************** @@ -189,7 +188,7 @@ void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam, usingWinMain = true; // Install default debug handler - qInstallMsgHandler(qWinMsgHandler); + qInstallMessageHandler(qWinMessageHandler); // Create command line argv = qWinCmdLine(cmdParam, int(strlen(cmdParam)), argc); -- cgit v1.2.3