main.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Project PhotoBunny
  3. * 2014 Gwilyn Saunders
  4. */
  5. #include "slidewindow.h"
  6. #include <QApplication>
  7. #include <QtCore>
  8. void customMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) {
  9. Q_UNUSED(context);
  10. QString dt = QDateTime::currentDateTime().toString("mm:ss");
  11. QString txt = QString("[%1] ").arg(dt);
  12. switch (type) {
  13. case QtDebugMsg:
  14. txt += QString("{Debug} \t\t %1").arg(msg);
  15. break;
  16. case QtWarningMsg:
  17. txt += QString("{Warning} \t %1").arg(msg);
  18. break;
  19. case QtCriticalMsg:
  20. txt += QString("{Critical} \t %1").arg(msg);
  21. break;
  22. case QtFatalMsg:
  23. txt += QString("{Fatal} \t\t %1").arg(msg);
  24. abort();
  25. break;
  26. }
  27. QFile outFile(QDir::homePath() + "/PhotoBunny_log.txt");
  28. outFile.open(QIODevice::WriteOnly | QIODevice::Append);
  29. QTextStream textStream(&outFile);
  30. textStream << txt << "\r\n";
  31. outFile.close();
  32. }
  33. int main(int argc, char *argv[]) {
  34. //refresh log
  35. QString dt = QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm");
  36. QFile outFile(QDir::homePath() + "/PhotoBunny_log.txt");
  37. outFile.open(QIODevice::WriteOnly);
  38. QTextStream textStream(&outFile);
  39. textStream << "FB Slideshow started on " << dt << "\r\n";
  40. textStream << "------------------------------------\r\n";
  41. outFile.close();
  42. //replace qDebug handler
  43. qInstallMessageHandler(customMessageHandler);
  44. QApplication a(argc, argv);
  45. SlideWindow w;
  46. return a.exec();
  47. }