#if ((Q == 1) || (Q == 2) || (Q == 3)) #include #else #include #endif #include #include #include #if (Q == 2) #define DEF_LOGGER(x) \ { \ std::cout << x << std::endl; \ qDebug(x); \ } #else #define DEF_LOGGER(x) \ { \ std::cout << x << std::endl; \ } #endif #if (Q != 3) void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) { bool babort = false; const char* file = context.file ? context.file : ""; const char* function = context.function ? context.function : ""; std::stringstream log; log << "messageHandler (" << file << ":" << context.line << ", " << function << "). Message: " << msg.toStdString(); bool error = false; std::string stype; switch (type) { case QtDebugMsg: stype = "DEBUG"; break; case QtWarningMsg: stype = "WARNING"; break; case QtInfoMsg: stype = "INFO"; break; case QtCriticalMsg: stype = "ERROR"; break; case QtFatalMsg: stype = "FATAL"; babort = true; } if (error) { std::cerr << stype << "." << log.str() << std::endl; } else { std::cout << stype << "." << log.str() << std::endl; } if (babort) { abort(); } } #endif int main(int argc, char* argv[]) { #if (Q != 3) DEF_LOGGER("before qInstallMessageHandler"); qInstallMessageHandler(messageHandler); DEF_LOGGER("after qInstallMessageHandler"); #endif DEF_LOGGER("before QxxxxApplication"); #if ((Q == 1) || (Q == 2) || (Q == 3)) QApplication a(argc, argv); #else QCoreApplication a(argc, argv); #endif DEF_LOGGER("before QxxxxApplication"); DEF_LOGGER("QQ tras"); return a.exec(); }