Hi dear ,

i try to use qInstallMessageHandler on not QTGui app -> QCoreApplication..
i can not find the mistake or why i can not install qInstallMessageHandler(MessageRewrite); befor init QCoreApplication
the compiler only say :
main.cpp:20:13: warning: enumeration value 'QtTraceMsg' not handled in switch [-Wswitch]
switch (type) {
and wen i insert qInstallMessageHandler(MessageRewrite); dont build on mac apple..
i need this on linux server ... to build comand of a cms..

can you find the point?


Qt Code:
  1. #include <QCoreApplication>
  2. #include <QDebug>
  3. #include <QSocketNotifier>
  4. #include <QTextStream>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h> //Provides STDIN_FILENO
  8. /// log file handler here postfix incomming pipe handle...
  9. #include "qlogger.h" // from https://github.com/francescmm/qt-coding/tree/master/QLogger
  10.  
  11. #if 0 //// 1 or 0 to disable qDebug = PEEPME
  12. #define PEEPME qDebug
  13. #else
  14. #define PEEPME if (0) qDebug
  15. #endif
  16.  
  17. void MessageRewrite(QtMsgType type, const char *msg) {
  18. const QString modrewriteMSG = QString::fromUtf8(msg); /// i hope is utf-8
  19. //DebugLevel, InfoLevel, WarnLevel, ErrorLevel, FatalLevel
  20. switch (type) {
  21. case QtDebugMsg:
  22. QLogger::QLog_("PipeApp", QLogger::InfoLevel, modrewriteMSG);
  23. break;
  24. case QtWarningMsg:
  25. QLogger::QLog_("PipeApp", QLogger::InfoLevel, modrewriteMSG);
  26. break;
  27. case QtCriticalMsg:
  28. QLogger::QLog_("PipeApp", QLogger::InfoLevel, modrewriteMSG);
  29. break;
  30. case QtFatalMsg:
  31. QLogger::QLog_("PipeApp", QLogger::InfoLevel, modrewriteMSG);
  32. abort();
  33. }
  34. }
  35. //// switch to qt5
  36. #define MEMOVERSIONCONFIG \
  37. QString("/Users/pro/Qt5-Source/current/bin/")
  38. #define __APPVERSION__ \
  39. QString("Ve.0.1.0")
  40. #define __APPNAME__ \
  41. QString("DComunicator")
  42. const int pointo = 76;
  43. /* catch event from QCoreApplication if haveit more */
  44. #define osApplication \
  45. (static_cast<PipeApp*>(QCoreApplication::instance()))
  46.  
  47. class PipeApp : public QCoreApplication {
  48.  
  49. Q_OBJECT
  50.  
  51. public:
  52. PipeApp(int &argc, char **argv)
  53. : QCoreApplication(argc, argv) {
  54. this->setApplicationName(__APPNAME__);
  55. QTextStream out(stdout); /// stdin
  56. QString str("*");
  57. setOrganizationName("Pipe STREAM");
  58. setOrganizationDomain("Postfix-Drupal-Handshake");
  59. manager = QLogger::QLoggerManager::getInstance();
  60. manager->addDestination("pipelog.log", __APPNAME__, QLogger::InfoLevel);
  61. notifier = new QSocketNotifier(STDIN_FILENO, QSocketNotifier::Read);
  62. connect(notifier, SIGNAL(activated(int)), this, SLOT(handleMail()));
  63. out << "### Hi dear Postfix MX write your chunk please,\n i need from mail & remote host ok? i am qt version -> " << QT_VERSION;
  64. out << "\n";
  65. out.flush();
  66. };
  67.  
  68. signals:
  69. void textReceived(QString message);
  70. public slots:
  71.  
  72. void handleMail() {
  73. QTextStream qin(stdin);
  74. QString line = qin.readLine();
  75. QLogger::QLog_(__APPNAME__, QLogger::InfoLevel,line);
  76. PEEPME() << "#incomming postfix chat:\n" << line;
  77. // later emit textReceived(line);
  78. };
  79.  
  80. protected:
  81.  
  82. bool event(QEvent *ev) {
  83. const int weather = ev->type();
  84. PEEPME() << "### run event -> " << weather;
  85. bool cursor;
  86. cursor = QCoreApplication::event(ev);
  87. return cursor;
  88. };
  89.  
  90. void pipeclose() {
  91. osApplication->quit();
  92. };
  93. QLogger::QLoggerManager *manager;
  94. QSocketNotifier* notifier;
  95. };
  96.  
  97. int main(int argc, char *argv[]) {
  98. /// qInstallMessageHandler(MessageRewrite);
  99. /// qInstallMessageHandler qt5 on only console fail
  100. PipeApp app(argc, argv);
  101. return app.exec();
  102. }
  103.  
  104. #include "main.moc"
To copy to clipboard, switch view to plain text mode