diff --git a/main.cpp b/main.cpp --- a/main.cpp +++ b/main.cpp @@ -28,6 +28,7 @@ MainWindow* pMainWindow; void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { + // TODO: don't call MainWindow::messageHandler if window is destroyed pMainWindow->messageHandler(type, context, msg); } diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -192,6 +192,7 @@ MainWindow::~MainWindow() serialPort.close(); } delete ui; + ui = NULL; // we check if ui is deleted in messageHandler } void MainWindow::setupAboutDialog() @@ -728,10 +729,10 @@ void MainWindow::messageHandler(QtMsgTyp break; } - ui->ptLog->appendPlainText(logString); + if (ui != NULL) ui->ptLog->appendPlainText(logString); std::cerr << logString.toStdString() << std::endl; - if (type != QtDebugMsg) + if (type != QtDebugMsg && ui != NULL) { ui->statusBar->showMessage(msg, 5000); }