main.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "mainwindow.h"
  2. #include "launchpage.h"
  3. #include <QApplication>
  4. #include <QElapsedTimer>
  5. #include <QDebug>
  6. #include <QSplitter>
  7. #include <QTextEdit>
  8. //重定向qdebug的打印
  9. void log_out_put(QtMsgType type, const QMessageLogContext& context, const QString& msg);
  10. /**
  11. * @brief 重定向qdebug的打印
  12. * @param type
  13. * @param context
  14. * @param msg
  15. */
  16. void log_out_put(QtMsgType type, const QMessageLogContext& context, const QString& msg)
  17. {
  18. QByteArray localMsg = msg.toLocal8Bit();
  19. switch (type) {
  20. case QtDebugMsg:
  21. fprintf(stdout, "[Debug] %s \n-------------->(%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
  22. break;
  23. // case QtInfoMsg:
  24. // fprintf(stdout, "[Info] %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
  25. // context.function); break;
  26. case QtWarningMsg:
  27. fprintf(stdout, "[Warning] %s \n-------------->(%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
  28. break;
  29. case QtCriticalMsg:
  30. fprintf(stdout, "[Critical] %s \n-------------->(%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
  31. break;
  32. case QtFatalMsg:
  33. fprintf(stdout, "Fatal: %s \n-------------->(%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
  34. abort();
  35. break;
  36. default:
  37. fprintf(stdout, "[Debug] %s \n-------------->(%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
  38. break;
  39. }
  40. #ifndef QT_NO_DEBUG_OUTPUT
  41. fflush(stdout);
  42. #endif
  43. }
  44. int main(int argc, char* argv[])
  45. {
  46. QApplication a(argc, argv);
  47. #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
  48. QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  49. #endif
  50. qInstallMessageHandler(log_out_put);
  51. QFont f = a.font();
  52. f.setFamily("微软雅黑");
  53. a.setFont(f);
  54. QElapsedTimer cost;
  55. cost.start();
  56. LaunchPage w;
  57. w.show();
  58. #if 0
  59. MainWindow w;
  60. qDebug() << "window build cost:" << cost.elapsed() << " ms";
  61. w.show();
  62. #endif
  63. return (a.exec());
  64. }