summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.cpp
diff options
context:
space:
mode:
authorAurindam Jana <aurindam.jana@nokia.com>2011-11-08 10:45:18 +0100
committerQt by Nokia <qt-info@nokia.com>2011-11-08 17:20:39 +0100
commit124044613dde9a9596312102ca377bc74ed08165 (patch)
tree8407d0d8676ab32c67bda2f6878d6f3884eec7fc /src/corelib/global/qglobal.cpp
parenta4f446704e7e02e25c02edb9d316513a482bae9a (diff)
QGlobal: Define a default message handler
Currently, qInstallMsgHandler() does not return the handle to the default message handler. This patch defines a default message handler. This is returned by qInstallMsgHandler() when called for the first time. A call to qInstallMsgHandler(0) will restore the default message handler as was the case previously. Change-Id: I42f06654d45fb0e633f3c6d912fc8f05c23249aa Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r--src/corelib/global/qglobal.cpp42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 453c4a96a8..91ac521a0b 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -2026,25 +2026,11 @@ extern bool usingWinMain;
extern Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char* str);
#endif
-QtMsgHandler qInstallMsgHandler(QtMsgHandler h)
-{
- QtMsgHandler old = handler;
- handler = h;
-#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
- if (!handler && usingWinMain)
- handler = qWinMsgHandler;
-#endif
- return old;
-}
-
/*!
\internal
*/
-void qt_message_output(QtMsgType msgType, const char *buf)
+static void qDefaultMsgHandler(QtMsgType, const char *buf)
{
- if (handler) {
- (*handler)(msgType, buf);
- } else {
#if defined(Q_CC_MWERKS) && defined(Q_OS_MACX)
mac_default_handler(buf);
#elif defined(Q_OS_WINCE)
@@ -2067,7 +2053,31 @@ void qt_message_output(QtMsgType msgType, const char *buf)
fprintf(stderr, "%s\n", buf);
fflush(stderr);
#endif
- }
+}
+
+QtMsgHandler qInstallMsgHandler(QtMsgHandler h)
+{
+ //if handler is 0, set it to the
+ //default message handler
+ if (!handler)
+ handler = qDefaultMsgHandler;
+ QtMsgHandler old = handler;
+ handler = h;
+#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
+ if (!handler && usingWinMain)
+ handler = qWinMsgHandler;
+#endif
+ return old;
+}
+
+/*!
+ \internal
+*/
+void qt_message_output(QtMsgType msgType, const char *buf)
+{
+ if (!handler)
+ handler = qDefaultMsgHandler;
+ (*handler)(msgType, buf);
if (msgType == QtFatalMsg
|| (msgType == QtWarningMsg