]> sigrok.org Git - pulseview.git/commitdiff
MainWindow: Move show_session_error to signals
authorVesa-Pekka Palmu <redacted>
Thu, 24 Nov 2022 16:58:38 +0000 (18:58 +0200)
committerSoeren Apel <redacted>
Wed, 17 May 2023 12:53:14 +0000 (14:53 +0200)
Before various capture error handlers called Mainwindow::show_session_error()
directly, and thus outside of the main UI thread. Qt widgets aren't thread-
safe and thus this resulted in crashes or freezes at least on OSX.

pv/mainwindow.cpp
pv/mainwindow.hpp
pv/session.cpp
pv/session.hpp

index b2a130a737a048f7b259b61e8fa72a2fa79fb9b8..8646175e2b32f7a6b7f0a7ec7233f07d136d77fb 100644 (file)
@@ -79,6 +79,8 @@ MainWindow::MainWindow(DeviceManager &device_manager, QWidget *parent) :
 {
        setup_ui();
        restore_ui_settings();
+       connect(this, SIGNAL(session_error_raised(const QString, const QString)),
+               this, SLOT(on_session_error_raised(const QString, const QString)));
 }
 
 MainWindow::~MainWindow()
@@ -193,6 +195,9 @@ shared_ptr<views::ViewBase> MainWindow::add_view(views::ViewType type,
                qobject_cast<views::ViewBase*>(v.get()),
                SLOT(trigger_event(int, util::Timestamp)));
 
+       connect(&session, SIGNAL(session_error_raised(const QString, const QString)),
+               this, SLOT(on_session_error_raised(const QString, const QString)));
+
        if (type == views::ViewTypeTrace) {
                views::trace::View *tv =
                        qobject_cast<views::trace::View*>(v.get());
@@ -691,8 +696,7 @@ void MainWindow::on_run_stop_clicked()
                        if (any_running)
                                s->stop_capture();
                        else
-                               s->start_capture([&](QString message) {
-                                       show_session_error("Capture failed", message); });
+                               s->start_capture([&](QString message) {Q_EMIT session_error_raised("Capture failed", message);});
        } else {
 
                shared_ptr<Session> session = last_focused_session_;
@@ -702,8 +706,7 @@ void MainWindow::on_run_stop_clicked()
 
                switch (session->get_capture_state()) {
                case Session::Stopped:
-                       session->start_capture([&](QString message) {
-                               show_session_error("Capture failed", message); });
+                       session->start_capture([&](QString message) {Q_EMIT session_error_raised("Capture failed", message);});
                        break;
                case Session::AwaitingTrigger:
                case Session::Running:
@@ -981,4 +984,8 @@ void MainWindow::on_close_current_tab()
        on_tab_close_requested(tab);
 }
 
+void MainWindow::on_session_error_raised(const QString text, const QString info_text) {
+       MainWindow::show_session_error(text, info_text);
+}
+
 } // namespace pv
index e10d1817f947ecb68387cf2f8bd154a3736050cf..493e3a55cc0dec32b3ca6e1471138dd0a0bdeac7 100644 (file)
@@ -115,8 +115,12 @@ private:
 
        virtual bool restoreState(const QByteArray &state, int version = 0);
 
+Q_SIGNALS:
+       void session_error_raised(const QString text, const QString info_text);
+
 public Q_SLOTS:
        void on_run_stop_clicked();
+       void on_session_error_raised(const QString text, const QString info_text);
 
 private Q_SLOTS:
        void on_add_view(ViewType type, Session *session);
index f992d9f1f3a98bec7a0cad69b954b431bc13692b..0e17a07bb05f9c663c139d5ed17ad6c965e8939e 100644 (file)
@@ -776,7 +776,7 @@ void Session::load_file(QString file_name, QString setup_file_name,
        main_bar_->update_device_list();
 
        start_capture([&, errorMessage](QString infoMessage) {
-               MainWindow::show_session_error(errorMessage, infoMessage); });
+               Q_EMIT session_error_raised(errorMessage, infoMessage); });
 
        // Only set save path if we loaded an srzip file
        if (dynamic_pointer_cast<devices::SessionFile>(device_))
index 91f98b581b8c0ed2a342321caf075cedff279b2d..ba48a4074d555de95d9c10ea17b00a836f006cf9 100644 (file)
@@ -264,6 +264,7 @@ Q_SIGNALS:
        void data_received();
 
        void add_view(ViewType type, Session *session);
+       void session_error_raised(const QString text, const QString info_text);
 
 public Q_SLOTS:
        void on_data_saved();