From d5f310e8285e783ec914a9e75d2230731c1868fe Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 10 Oct 2017 20:54:59 +0200 Subject: Fixed crash on exit properly --- src/mainwindow.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1036cbb..daf344d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -139,16 +139,21 @@ MainWindow::MainWindow(QWidget *parent) : MainWindow::~MainWindow() { + // Release all dock widgets before deleting so we don't accidentally delete them + // Also fixes that annoying crash when closing + QList allDockWidgets = findChildren(); + for(QDockWidget *w : allDockWidgets) { + if(w->widget()) { + w->widget()->setParent(0); + } + } + delete ui; } void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QWidget *widget) { - QDockWidget *dock = new QDockWidget(widget->windowTitle(), this); - dock->setWidget(widget); - addDockWidget(area, dock); - - /* + // create a list for the dock widgets we're appending to QList allDockWidgets = findChildren(); QVector areaDockWidgets; for(QDockWidget *w : allDockWidgets) { @@ -157,12 +162,15 @@ void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QWidget *widget) } } + QDockWidget *dock = new QDockWidget(widget->windowTitle(), this); + dock->setWidget(widget); + if(areaDockWidgets.empty()) { // no other widgets - addDockWidget(area, widget); + addDockWidget(area, dock); } else { - tabifyDockWidget(areaDockWidgets.last(), widget); - }*/ + tabifyDockWidget(areaDockWidgets.last(), dock); + } } void MainWindow::newTab(const QUrl &url) -- cgit v1.2.1