From e6b2fb8df994a4cb3de2f9896aea64858eb3d238 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Tue, 6 Jul 2010 13:39:41 +0200 Subject: Prevent a recursive debug output loop when writing to the logger widget. (On Maemo5 the input method may generate a qWarning when someone clicks into the logger widget, which leads to an endless output recursion) Reviewed-by: Harald Fernengel --- tools/qml/main.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index d0817bc..d5ad9ad 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include "qdeclarativetester.h" QT_USE_NAMESPACE @@ -89,19 +90,25 @@ void showWarnings() } } +static QAtomicInt recursiveLock(0); + void myMessageOutput(QtMsgType type, const char *msg) { + QString strMsg = QString::fromLatin1(msg); + if (!logger.isNull() && !QCoreApplication::closingDown()) { - QString strMsg = QString::fromAscii(msg); - QMetaObject::invokeMethod(logger.data(), "append", Q_ARG(QString, strMsg)); + if (recursiveLock.testAndSetOrdered(0, 1)) { + QMetaObject::invokeMethod(logger.data(), "append", Q_ARG(QString, strMsg)); + recursiveLock = 0; + } } else { - warnings += msg; + warnings += strMsg; warnings += QLatin1Char('\n'); } if (systemMsgOutput) { // Windows systemMsgOutput(type, msg); } else { // Unix - fprintf(stderr, "%s\n",msg); + fprintf(stderr, "%s\n", msg); fflush(stderr); } } -- cgit v0.12