From: Vesa-Pekka Palmu Date: Thu, 24 Nov 2022 16:58:38 +0000 (+0200) Subject: MainWindow: Move show_session_error to signals X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ae8dd8753ec0804f9c87938c13b082f8f39b05b0;p=pulseview.git MainWindow: Move show_session_error to signals 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. --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index b2a130a7..8646175e 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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 MainWindow::add_view(views::ViewType type, qobject_cast(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(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 = 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 diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index e10d1817..493e3a55 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -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); diff --git a/pv/session.cpp b/pv/session.cpp index f992d9f1..0e17a07b 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -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(device_)) diff --git a/pv/session.hpp b/pv/session.hpp index 91f98b58..ba48a407 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -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();