From 835279e9a6ca98058e83e65b6fe1a54ca35ed49a Mon Sep 17 00:00:00 2001 From: pixhawk Date: Mon, 3 Jan 2011 11:10:05 +0100 Subject: [PATCH] Fixed multi-thread message window bug, mainwindow should not hang any more on message windows from comm threads --- src/comm/MAVLinkProtocol.cc | 10 +++------- src/ui/MainWindow.cc | 30 +++++++++++++++++++++++++----- src/ui/MainWindow.h | 21 +++++---------------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index fc9ccea..38e280a 100644 --- a/src/comm/MAVLinkProtocol.cc +++ b/src/comm/MAVLinkProtocol.cc @@ -164,13 +164,9 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b) if (heartbeat.mavlink_version != MAVLINK_VERSION) { // Bring up dialog to inform user - QMessageBox msgBox(MainWindow::instance()); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setText(tr("The MAVLink protocol version on the MAV and QGroundControl mismatch!")); - msgBox.setInformativeText(tr("It is unsafe to use different MAVLink versions. QGroundControl therefore refuses to connect to system %1, which sends MAVLink version %2 (QGroundControl uses version %3).").arg(message.sysid).arg(heartbeat.mavlink_version).arg(MAVLINK_VERSION)); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); + MainWindow::instance()->showCriticalMessage(tr("The MAVLink protocol version on the MAV and QGroundControl mismatch!"), + tr("It is unsafe to use different MAVLink versions. QGroundControl therefore refuses to connect to system %1, which sends MAVLink version %2 (QGroundControl uses version %3).").arg(message.sysid).arg(heartbeat.mavlink_version).arg(MAVLINK_VERSION)); + // Ignore this message and continue gracefully continue; diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 336842f..56b3cb8 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -882,17 +882,37 @@ void MainWindow::reloadStylesheet() delete styleSheet; } +/** + * The status message will be overwritten if a new message is posted to this function + * + * @param status message text + * @param timeout how long the status should be displayed + */ void MainWindow::showStatusMessage(const QString& status, int timeout) { - Q_UNUSED(status); - Q_UNUSED(timeout); - //statusBar->showMessage(status, timeout); + statusBar->showMessage(status, timeout); } +/** + * The status message will be overwritten if a new message is posted to this function. + * it will be automatically hidden after 5 seconds. + * + * @param status message text + */ void MainWindow::showStatusMessage(const QString& status) { - Q_UNUSED(status); - //statusBar->showMessage(status, 5); + statusBar->showMessage(status, 5); +} + +void MainWindow::showCriticalMessage(const QString& title, const QString& message) +{ + QMessageBox msgBox(MainWindow::instance()); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setText(title); + msgBox.setInformativeText(message); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.exec(); } /** diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 4e4302e..9ff4500 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -92,24 +92,13 @@ public slots: // /** @brief Store the mainwindow settings */ // void storeSettings(); - /** - * @brief Shows a status message on the bottom status bar - * - * The status message will be overwritten if a new message is posted to this function - * - * @param status message text - * @param timeout how long the status should be displayed - */ + /** @brief Shows a status message on the bottom status bar */ void showStatusMessage(const QString& status, int timeout); - /** - * @brief Shows a status message on the bottom status bar - * - * The status message will be overwritten if a new message is posted to this function. - * it will be automatically hidden after 5 seconds. - * - * @param status message text - */ + /** @brief Shows a status message on the bottom status bar */ void showStatusMessage(const QString& status); + /** @brief Shows a critical message as popup or as widget */ + void showCriticalMessage(const QString& title, const QString& message); + void addLink(); void addLink(LinkInterface* link); void configure();