diff --git a/OSBindings/Qt/main.cpp b/OSBindings/Qt/main.cpp index 59912a79f..89cbb1940 100644 --- a/OSBindings/Qt/main.cpp +++ b/OSBindings/Qt/main.cpp @@ -17,7 +17,10 @@ int main(int argc, char *argv[]) // TODO: something with QCommandLineParser to accept a file to launch. QApplication a(argc, argv); - MainWindow w; - w.show(); + + MainWindow *w = new MainWindow(); + w->setAttribute(Qt::WA_DeleteOnClose); + w->show(); + return a.exec(); } diff --git a/OSBindings/Qt/mainwindow.cpp b/OSBindings/Qt/mainwindow.cpp index fb5eec284..7cf8b491c 100644 --- a/OSBindings/Qt/mainwindow.cpp +++ b/OSBindings/Qt/mainwindow.cpp @@ -51,6 +51,9 @@ MainWindow::~MainWindow() { // to write to the audioOutput while it is being shut down. timer.reset(); + // Shut down the scan target while it still has a context for cleanup. + ui->openGLWidget->stop(); + // Stop the audio output, and its thread. if(audioOutput) { audioThread.performAsync([this] { @@ -71,6 +74,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { // i.e. assume they were closing that document, not the application. // if(mainWindowCount == 1 && machine) { // MainWindow *const other = new MainWindow; +// other->setAttribute(Qt::WA_DeleteOnClose); // other->show(); // } QMainWindow::closeEvent(event); @@ -103,6 +107,7 @@ void MainWindow::createActions() { MainWindow *other = new MainWindow; other->tile(this); + other->setAttribute(Qt::WA_DeleteOnClose); other->show(); }); fileMenu->addAction(newAct); @@ -119,6 +124,7 @@ void MainWindow::createActions() { if(machine) { MainWindow *const other = new MainWindow(fileName); other->tile(this); + other->setAttribute(Qt::WA_DeleteOnClose); other->show(); } else { launchFile(fileName); diff --git a/OSBindings/Qt/scantargetwidget.cpp b/OSBindings/Qt/scantargetwidget.cpp index a9aab5e32..7663e4f4b 100644 --- a/OSBindings/Qt/scantargetwidget.cpp +++ b/OSBindings/Qt/scantargetwidget.cpp @@ -75,3 +75,9 @@ void ScanTargetWidget::setScanProducer(MachineTypes::ScanProducer *producer) { this->producer = producer; repaint(); } + +void ScanTargetWidget::stop() { + makeCurrent(); + scanTarget.reset(); + isConnected = false; +} diff --git a/OSBindings/Qt/scantargetwidget.h b/OSBindings/Qt/scantargetwidget.h index 520df2153..17a4f7c0c 100644 --- a/OSBindings/Qt/scantargetwidget.h +++ b/OSBindings/Qt/scantargetwidget.h @@ -18,6 +18,8 @@ class ScanTargetWidget : public QOpenGLWidget // handed a suitable scan target as soon as one exists. void setScanProducer(MachineTypes::ScanProducer *); + void stop(); + protected: void initializeGL() override; void resizeGL(int w, int h) override;