diff options
-rw-r--r-- | src/corelib/global/qglobal.cpp | 42 | ||||
-rw-r--r-- | tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 12 |
2 files changed, 38 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 diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 772fd9fd04..f33a7eef5a 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -54,6 +54,7 @@ private slots: void debugWithQBool() const; void veryLongWarningMessage() const; void qDebugQStringRef() const; + void defaultMessagehandler() const; }; void tst_QDebug::assignment() const @@ -154,5 +155,16 @@ void tst_QDebug::qDebugQStringRef() const } } +void tst_QDebug::defaultMessagehandler() const +{ + QtMsgHandler defaultMessageHandler1 = qInstallMsgHandler(0); + QtMsgHandler defaultMessageHandler2 = qInstallMsgHandler(myMessageHandler); + bool same = (*defaultMessageHandler1 == *defaultMessageHandler2); + QVERIFY(same); + QtMsgHandler messageHandler = qInstallMsgHandler(0); + same = (*messageHandler == *myMessageHandler); + QVERIFY(same); +} + QTEST_MAIN(tst_QDebug); #include "tst_qdebug.moc" |