From: Soeren Apel Date: Tue, 4 Oct 2016 17:32:58 +0000 (+0200) Subject: MainWindow: Use regular pointer for QDockWidgets X-Git-Tag: pulseview-0.4.0~237 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cbf7b5db5c3c04b95daf77bc0e6dc112c15e0195;p=pulseview.git MainWindow: Use regular pointer for QDockWidgets Using shared_ptrs conflicts with the Qt memory management, so we can't use them if we don't have control over when those objects are deleted by Qt. In this case, we need to handle the dock widgets properly. --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 2f82cb19..775f9dec 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -146,7 +146,7 @@ shared_ptr MainWindow::get_active_view() const // Get the view contained in the dock widget for (auto entry : view_docks_) - if (entry.first.get() == dock) + if (entry.first == dock) return entry.second; return nullptr; @@ -163,12 +163,12 @@ shared_ptr MainWindow::add_view(const QString &title, assert(main_window); if (type == views::ViewTypeTrace) { - shared_ptr dock = make_shared(title, main_window); + QDockWidget* dock = new QDockWidget(title, main_window); dock->setObjectName(title); - main_window->addDockWidget(Qt::TopDockWidgetArea, dock.get()); + main_window->addDockWidget(Qt::TopDockWidgetArea, dock); // Insert a QMainWindow into the dock widget to allow for a tool bar - QMainWindow *dock_main = new QMainWindow(dock.get()); + QMainWindow *dock_main = new QMainWindow(dock); dock_main->setWindowFlags(Qt::Widget); // Remove Qt::Window flag shared_ptr v = @@ -469,7 +469,7 @@ void MainWindow::on_view_close_clicked() shared_ptr view; for (auto entry : view_docks_) - if (entry.first.get() == dock) + if (entry.first == dock) view = entry.second; // Deregister the view diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index e9cecfb1..2448a357 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -118,8 +118,7 @@ private: std::list< std::shared_ptr > sessions_; - std::map< std::shared_ptr, - std::shared_ptr > view_docks_; + std::map< QDockWidget*, std::shared_ptr > view_docks_; std::map< std::shared_ptr, QMainWindow*> session_windows_;