Advertisement
dkonigsberg

QDebug Hook

Sep 29th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef QT_NO_DEBUG_OUTPUT
  2. void logMessageHandler(QtMsgType type, const char *msg)
  3. {
  4.     QString debugdate = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
  5.     switch (type)
  6.     {
  7.     case QtDebugMsg:
  8.         debugdate += "[D]";
  9.         break;
  10.     case QtWarningMsg:
  11.         debugdate += "[W]";
  12.         break;
  13.     case QtCriticalMsg:
  14.         debugdate += "[C]";
  15.         break;
  16.     case QtFatalMsg:
  17.         debugdate += "[F]";
  18.         break;
  19.     }
  20.  
  21.     fprintf(stderr, "%s %s\n", debugdate.toLatin1().data(), msg);
  22.  
  23.     if (QtFatalMsg == type) {
  24.         abort();
  25.     }
  26. }
  27. #endif
  28.  
  29. int main(int argc, char **argv)
  30. {
  31. #ifndef QT_NO_DEBUG_OUTPUT
  32.     qInstallMsgHandler(logMessageHandler);
  33. #endif
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement