Create Qt5 compatible version of trace event handler.

Qt5 deprecates the way this was done before.

Change-Id: Ic66bce2d1ffcb572a9ed9345abbbbc6bb6475af0
This commit is contained in:
Dominik Riebeling 2013-01-28 21:18:12 +01:00
parent d06779d987
commit 2dab7c9775
4 changed files with 32 additions and 0 deletions

View file

@ -30,7 +30,11 @@ Q_IMPORT_PLUGIN(qtaccessiblewidgets)
int main( int argc, char ** argv ) { int main( int argc, char ** argv ) {
#if QT_VERSION < 0x050000
qInstallMsgHandler(SysTrace::debug); qInstallMsgHandler(SysTrace::debug);
#else
qInstallMessageHandler(SysTrace::debug);
#endif
QApplication app( argc, argv ); QApplication app( argc, argv );
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
QDir dir(QApplication::applicationDirPath()); QDir dir(QApplication::applicationDirPath());

View file

@ -183,7 +183,11 @@ void RbUtilQt::shutdown(void)
// restore default message handler to prevent trace accesses during // restore default message handler to prevent trace accesses during
// object destruction -- the trace object could already be destroyed. // object destruction -- the trace object could already be destroyed.
// Fixes segfaults on exit. // Fixes segfaults on exit.
#if QT_VERSION < 0x050000
qInstallMsgHandler(0); qInstallMsgHandler(0);
#else
qInstallMessageHandler(0);
#endif
SysTrace::save(); SysTrace::save();
this->close(); this->close();
} }

View file

@ -93,6 +93,7 @@ void SysTrace::savePreviousTrace(void)
return; return;
} }
#if QT_VERSION < 0x050000
void SysTrace::debug(QtMsgType type, const char* msg) void SysTrace::debug(QtMsgType type, const char* msg)
{ {
(void)type; (void)type;
@ -109,6 +110,25 @@ void SysTrace::debug(QtMsgType type, const char* msg)
repeat++; 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) void SysTrace::flush(void)
{ {

View file

@ -29,7 +29,11 @@ class SysTrace : public QDialog
Q_OBJECT Q_OBJECT
public: public:
SysTrace(QWidget *parent); SysTrace(QWidget *parent);
#if QT_VERSION < 0x050000
static void debug(QtMsgType type, const char* msg); 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 QString getTrace() {return debugbuffer;}
static void save(QString filename = ""); static void save(QString filename = "");
private: private: