diff --git a/main.cpp b/main.cpp index b0e0e07e..689b3467 100644 --- a/main.cpp +++ b/main.cpp @@ -34,27 +34,48 @@ MainWindow *mainwin=NULL; -void MyOutputHandler(QtMsgType type, const char *msg) { +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) +void MyOutputHandler(QtMsgType type, const char *msgtxt) { +#else +void MyOutputHandler(QtMsgType type, const QMessageLogContext & context, const QString &msgtxt) { +#endif if (!mainwin) { + // qInstallMessageHandler(0); + +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + fprintf(stderr,"Pre/Post: %s\n",msgtxt.toLocal8Bit().constData()); +#else + fprintf(stderr,"Pre/Post: %s\n",msgtxt); +#endif return; } + QString msg,typestr; switch (type) { - case QtDebugMsg: - mainwin->Log(msg); - break; case QtWarningMsg: - mainwin->Log(QString("Warning: ")+msg); + typestr=QString("Warning: "); break; case QtFatalMsg: - mainwin->Log(QString("Fatal: ")+msg); + typestr=QString("Fatal: "); break; case QtCriticalMsg: - mainwin->Log(QString("Critical: ")+msg); + typestr=QString("Critical: "); + break; + default: + typestr=QString("Debug: "); break; - // Popup a messagebox - //abort(); } +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + msg=typestr+msgtxt+QString(" (%1:%2, %3)").arg(context.file).arg(context.line).arg(context.function); +#else + msg=typestr+msgtxt; +#endif + mainwin->Log(msg); + + if (type==QtFatalMsg) { + abort(); + } + //loglock.unlock(); } @@ -252,9 +273,9 @@ int main(int argc, char *argv[]) qDebug() << "Selected" << QApplication::font().family(); -#if QT_VERSION < QT_VERSION_CHECK(5,0,0) -// qInstallMessageHandler(MyOutputHandler); -//#else +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + qInstallMessageHandler(MyOutputHandler); +#else qInstallMsgHandler(MyOutputHandler); #endif //#endif diff --git a/mainwindow.cpp b/mainwindow.cpp index cf20ce95..d0359bdd 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -63,15 +63,16 @@ void MainWindow::Log(QString s) strlock.lock(); // only do this in the main thread? - for (int i=0;ilogText->appendPlainText(logbuffer[i]); + fprintf(stderr,"%s\n",logbuffer[i].toLocal8Bit().constData()); + } logbuffer.clear(); strlock.unlock(); //loglock.unlock(); } - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -218,6 +219,7 @@ MainWindow::~MainWindow() // Shutdown and Save the current User profile Profiles::Done(); + mainwin=NULL; delete ui; }