diff --git a/src/QGCMessageBox.h b/src/QGCMessageBox.h index 659a7a57cffcb8ee4f49e072aea2419b19058228..aef15f3d53844ef940fb6a2d40b4d57721330cdf 100644 --- a/src/QGCMessageBox.h +++ b/src/QGCMessageBox.h @@ -100,6 +100,7 @@ private: #ifdef QT_DEBUG if (qgcApp()->runningUnitTests()) { + qDebug() << "QGCMessageBox (unit testing)" << title << text; return UnitTest::_messageBox(icon, title, text, buttons, defaultButton); } else #endif diff --git a/src/qgcunittest/MainWindowTest.cc b/src/qgcunittest/MainWindowTest.cc index 408e95d870e695ec0dd530dc2b53161b4536bdb5..16e4c031ea8dc3af4bb45df91b81ed940b1c6890 100644 --- a/src/qgcunittest/MainWindowTest.cc +++ b/src/qgcunittest/MainWindowTest.cc @@ -81,8 +81,8 @@ void MainWindowTest::_connectWindowClose_test(void) linkMgr->connectLink(link); QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through - // On MainWindow close we should get a message box telling the user to disconnect first - setExpectedMessageBox(QGCMessageBox::Ok); + // On MainWindow close we should get a message box telling the user to disconnect first. Cancel should do nothing. + setExpectedMessageBox(QGCMessageBox::Cancel); _mainWindow->close(); QTest::qWait(1000); // Need to allow signals to move between threads checkExpectedMessageBox(); diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 9be412641f1d59ecee1dbb1c8e7ca503734827e7..25d60adc3e017e84417d14b538eba56546a5e26b 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -787,11 +787,23 @@ void MainWindow::closeEvent(QCloseEvent *event) } if (foundConnections) { - QGCMessageBox::warning(tr("QGroundControl close"), tr("There are still active connections to vehicles. Please disconnect all connections before closing QGroundControl.")); - event->ignore(); - return; + QGCMessageBox::StandardButton button = QGCMessageBox::warning(tr("QGroundControl close"), + tr("There are still active connections to vehicles. Do you want to disconnect these before closing?"), + QMessageBox::Yes | QMessageBox::Cancel, + QMessageBox::Cancel); + if (button == QMessageBox::Yes) { + foreach(LinkInterface* link, LinkManager::instance()->getLinks()) { + LinkManager::instance()->disconnectLink(link); + } + } else { + event->ignore(); + return; + } } + // This will process any remaining flight log save dialogs + qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents); + // Should not be any active connections foreach(LinkInterface* link, LinkManager::instance()->getLinks()) { Q_UNUSED(link);