From 2dab7c97751d34cf6fc888305f949d290c292f48 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Mon, 28 Jan 2013 21:18:12 +0100 Subject: Create Qt5 compatible version of trace event handler. Qt5 deprecates the way this was done before. Change-Id: Ic66bce2d1ffcb572a9ed9345abbbbc6bb6475af0 --- rbutil/rbutilqt/main.cpp | 4 ++++ rbutil/rbutilqt/rbutilqt.cpp | 4 ++++ rbutil/rbutilqt/systrace.cpp | 20 ++++++++++++++++++++ rbutil/rbutilqt/systrace.h | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/rbutil/rbutilqt/main.cpp b/rbutil/rbutilqt/main.cpp index 75b98cf35f..7d57f42290 100644 --- a/rbutil/rbutilqt/main.cpp +++ b/rbutil/rbutilqt/main.cpp @@ -30,7 +30,11 @@ Q_IMPORT_PLUGIN(qtaccessiblewidgets) int main( int argc, char ** argv ) { +#if QT_VERSION < 0x050000 qInstallMsgHandler(SysTrace::debug); +#else + qInstallMessageHandler(SysTrace::debug); +#endif QApplication app( argc, argv ); #if defined(Q_OS_MAC) QDir dir(QApplication::applicationDirPath()); diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index 5ea5002c8f..c5cdeb1cf7 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp @@ -183,7 +183,11 @@ void RbUtilQt::shutdown(void) // restore default message handler to prevent trace accesses during // object destruction -- the trace object could already be destroyed. // Fixes segfaults on exit. +#if QT_VERSION < 0x050000 qInstallMsgHandler(0); +#else + qInstallMessageHandler(0); +#endif SysTrace::save(); this->close(); } diff --git a/rbutil/rbutilqt/systrace.cpp b/rbutil/rbutilqt/systrace.cpp index f713a45d4c..943f34f7b9 100644 --- a/rbutil/rbutilqt/systrace.cpp +++ b/rbutil/rbutilqt/systrace.cpp @@ -93,6 +93,7 @@ void SysTrace::savePreviousTrace(void) return; } +#if QT_VERSION < 0x050000 void SysTrace::debug(QtMsgType type, const char* msg) { (void)type; @@ -109,6 +110,25 @@ void SysTrace::debug(QtMsgType type, const char* msg) repeat++; } } +#else +void SysTrace::debug(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + (void)type; + QByteArray localMsg = msg.toLocal8Bit(); + if(lastmessage != msg) { + lastmessage = msg; + flush(); + debugbuffer.append(msg + "\n"); +#if !defined(NODEBUG) + fprintf(stderr, "%s\n", localMsg.constData()); +#endif + repeat = 1; + } + else { + repeat++; + } +} +#endif void SysTrace::flush(void) { diff --git a/rbutil/rbutilqt/systrace.h b/rbutil/rbutilqt/systrace.h index 8658df1cba..092d115489 100644 --- a/rbutil/rbutilqt/systrace.h +++ b/rbutil/rbutilqt/systrace.h @@ -29,7 +29,11 @@ class SysTrace : public QDialog Q_OBJECT public: SysTrace(QWidget *parent); +#if QT_VERSION < 0x050000 static void debug(QtMsgType type, const char* msg); +#else + static void debug(QtMsgType type, const QMessageLogContext &context, const QString &msg); +#endif static QString getTrace() {return debugbuffer;} static void save(QString filename = ""); private: -- cgit v1.2.3