PDA

View Full Version : Why qInstallMessageHandler not run on console app?



patrik08
20th November 2013, 11:37
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?




#include <QCoreApplication>
#include <QDebug>
#include <QSocketNotifier>
#include <QTextStream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> //Provides STDIN_FILENO
/// log file handler here postfix incomming pipe handle...
#include "qlogger.h" // from https://github.com/francescmm/qt-coding/tree/master/QLogger

#if 0 //// 1 or 0 to disable qDebug = PEEPME
#define PEEPME qDebug
#else
#define PEEPME if (0) qDebug
#endif

void MessageRewrite(QtMsgType type, const char *msg) {
const QString modrewriteMSG = QString::fromUtf8(msg); /// i hope is utf-8
//DebugLevel, InfoLevel, WarnLevel, ErrorLevel, FatalLevel
switch (type) {
case QtDebugMsg:
QLogger::QLog_("PipeApp", QLogger::InfoLevel, modrewriteMSG);
break;
case QtWarningMsg:
QLogger::QLog_("PipeApp", QLogger::InfoLevel, modrewriteMSG);
break;
case QtCriticalMsg:
QLogger::QLog_("PipeApp", QLogger::InfoLevel, modrewriteMSG);
break;
case QtFatalMsg:
QLogger::QLog_("PipeApp", QLogger::InfoLevel, modrewriteMSG);
abort();
}
}
//// switch to qt5
#define MEMOVERSIONCONFIG \
QString("/Users/pro/Qt5-Source/current/bin/")
#define __APPVERSION__ \
QString("Ve.0.1.0")
#define __APPNAME__ \
QString("DComunicator")
const int pointo = 76;
/* catch event from QCoreApplication if haveit more */
#define osApplication \
(static_cast<PipeApp*>(QCoreApplication::instance()))

class PipeApp : public QCoreApplication {

Q_OBJECT

public:
PipeApp(int &argc, char **argv)
: QCoreApplication(argc, argv) {
this->setApplicationName(__APPNAME__);
QTextStream out(stdout); /// stdin
QString str("*");
setOrganizationName("Pipe STREAM");
setOrganizationDomain("Postfix-Drupal-Handshake");
manager = QLogger::QLoggerManager::getInstance();
manager->addDestination("pipelog.log", __APPNAME__, QLogger::InfoLevel);
notifier = new QSocketNotifier(STDIN_FILENO, QSocketNotifier::Read);
connect(notifier, SIGNAL(activated(int)), this, SLOT(handleMail()));
out << "### Hi dear Postfix MX write your chunk please,\n i need from mail & remote host ok? i am qt version -> " << QT_VERSION;
out << "\n";
out.flush();
};

signals:
void textReceived(QString message);
public slots:

void handleMail() {
QTextStream qin(stdin);
QString line = qin.readLine();
QLogger::QLog_(__APPNAME__, QLogger::InfoLevel,line);
PEEPME() << "#incomming postfix chat:\n" << line;
// later emit textReceived(line);
};

protected:

bool event(QEvent *ev) {
const int weather = ev->type();
PEEPME() << "### run event -> " << weather;
bool cursor;
cursor = QCoreApplication::event(ev);
return cursor;
};

void pipeclose() {
osApplication->quit();
};
QLogger::QLoggerManager *manager;
QSocketNotifier* notifier;
};

int main(int argc, char *argv[]) {
/// qInstallMessageHandler(MessageRewrite);
/// qInstallMessageHandler qt5 on only console fail
PipeApp app(argc, argv);
return app.exec();
}

#include "main.moc"