I followed the examples given in the docs and created my own little custom error handler like so:

Qt Code:
  1. #define now QTime::currentTime().toString("HH:mm:ss").toLocal8Bit().data()
  2. #define today QDate::currentDate().toString("d-M-yyyy").toLocal8Bit().data()
  3.  
  4. void handler(QtMsgType type, const char *msg)
  5. {
  6. #ifdef DEBUGMODE
  7. switch (type)
  8. {
  9. case QtDebugMsg:
  10. fprintf(stdout, "Debug: %s\n", msg);
  11. fprintf(stderr, "%s Debug: %s\n", now, msg);
  12. break;
  13. case QtWarningMsg:
  14. fprintf(stdout, "Warning: %s\n", msg);
  15. fprintf(stderr, "%s Warning: %s\n", now, msg);
  16. break;
  17. case QtCriticalMsg:
  18. fprintf(stdout, "Error: %s\n", msg);
  19. fprintf(stderr, "%s Error: %s\n", now, msg);
  20. break;
  21. case QtFatalMsg:
  22. fprintf(stdout, "FATAL ERROR: %s\n", msg);
  23. fprintf(stderr, "%s FATAL ERROR: %s\n", now, msg);
  24. abort();
  25. }
  26. #else //RELEASEMODE
  27. switch (type)
  28. {
  29. case QtDebugMsg:
  30. break;
  31. case QtWarningMsg:
  32. fprintf(stderr, "%s Warning: %s\n", now, msg);
  33. break;
  34. case QtCriticalMsg:
  35. fprintf(stderr, "%s Error: %s\n", now, msg);
  36. break;
  37. case QtFatalMsg:
  38. fprintf(stderr, "%s FATAL ERROR: %s\n", now, msg);
  39. abort();
  40. }
  41. #endif
  42. }
  43.  
  44. myErrorHandler::myErrorHandler(const char* outfile)
  45. {
  46. freopen(outfile, "w", stderr);
  47. setbuf(stdout, NULL);
  48. fprintf(stderr, "Running LASE.exe on %s at %s.\n", today, now);
  49. }
  50.  
  51. myErrorHandler::~myErrorHandler()
  52. {
  53. }
  54.  
  55. void myErrorHandler::install()
  56. {
  57. qInstallMsgHandler(handler);
  58. }
To copy to clipboard, switch view to plain text mode 

Now, I'm compiling with MSVC2010 so I'm getting the typical "C4996 ______ This function of variable may be unsafe blah blah blah" warning for freopen and setbuf. Personally, I prefer to address all warnings whenever possible, so I'd prefer to use a QDataStream for portability instead of the standard library.

The only way I can think of is to declare a global QDataStream variable with its device set to a global file, but I'd rather avoid setting more global variables if I can. Is this possible?

I suppose I could content myself with disabling those particular warnings, but I can't figure out the syntax.