]> sigrok.org Git - pulseview.git/commitdiff
MainWindow: Use regular pointer for QDockWidgets
authorSoeren Apel <redacted>
Tue, 4 Oct 2016 17:32:58 +0000 (19:32 +0200)
committerSoeren Apel <redacted>
Sun, 4 Dec 2016 13:37:36 +0000 (14:37 +0100)
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.

pv/mainwindow.cpp
pv/mainwindow.hpp

index 2f82cb19ca2c2fbea2ef67acf9e051e47cd6c51e..775f9dec90a53d628271f5580a829b60b2027035 100644 (file)
@@ -146,7 +146,7 @@ shared_ptr<views::ViewBase> 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<views::ViewBase> MainWindow::add_view(const QString &title,
        assert(main_window);
 
        if (type == views::ViewTypeTrace) {
-               shared_ptr<QDockWidget> dock = make_shared<QDockWidget>(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<views::TraceView::View> v =
@@ -469,7 +469,7 @@ void MainWindow::on_view_close_clicked()
        shared_ptr<views::ViewBase> view;
 
        for (auto entry : view_docks_)
-               if (entry.first.get() == dock)
+               if (entry.first == dock)
                        view = entry.second;
 
        // Deregister the view
index e9cecfb1deab73c4fcf3cb81578b3d5829c71c65..2448a3570d45b9f10187a480d6ef7a85dcf5a83d 100644 (file)
@@ -118,8 +118,7 @@ private:
 
        std::list< std::shared_ptr<Session> > sessions_;
 
-       std::map< std::shared_ptr<QDockWidget>,
-               std::shared_ptr<views::ViewBase> > view_docks_;
+       std::map< QDockWidget*, std::shared_ptr<views::ViewBase> > view_docks_;
 
        std::map< std::shared_ptr<Session>, QMainWindow*> session_windows_;