diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2012-04-02 13:48:06 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-20 08:37:06 +0200 |
commit | d9a1c2dff85635076ecaee3507427d750846c85c (patch) | |
tree | 5c60ddcb7815b6ea1789c84c7972ddda2e0a4e85 /doc/src/snippets | |
parent | a3f90fd44f822ae9d77c9d115934e18a9c7466fd (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'doc/src/snippets')
-rw-r--r-- | doc/src/snippets/code/src_corelib_global_qglobal.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/doc/src/snippets/code/src_corelib_global_qglobal.cpp b/doc/src/snippets/code/src_corelib_global_qglobal.cpp index 16f6783a52..dc6c3aa616 100644 --- a/doc/src/snippets/code/src_corelib_global_qglobal.cpp +++ b/doc/src/snippets/code/src_corelib_global_qglobal.cpp @@ -246,20 +246,21 @@ const TInputType &myMin(const TInputType &value1, const TInputType &value2) #include <stdio.h> #include <stdlib.h> -void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const char *msg) +void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { + QByteArray localMsg = msg.toLocal8Bit(); switch (type) { case QtDebugMsg: - fprintf(stderr, "Debug: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtWarningMsg: - fprintf(stderr, "Warning: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtCriticalMsg: - fprintf(stderr, "Critical: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtFatalMsg: - fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); abort(); } } |