Prevent Qt from crashing PV by only showing the first error
authorSoeren Apel <soeren@apelpie.net>
Wed, 18 Nov 2020 18:09:41 +0000 (19:09 +0100)
committerSoeren Apel <soeren@apelpie.net>
Wed, 18 Nov 2020 18:10:19 +0000 (19:10 +0100)
pv/dialogs/storeprogress.cpp
pv/dialogs/storeprogress.hpp

index 2bca3476c434b53ff65e99b4774145dbff248592..8699ccefdfbcca6fe2bae451f9c34072d0848717 100644 (file)
@@ -43,7 +43,8 @@ StoreProgress::StoreProgress(const QString &file_name,
        const Session &session, QWidget *parent) :
        QProgressDialog(tr("Saving..."), tr("Cancel"), 0, 0, parent),
        session_(file_name.toStdString(), output_format, options, sample_range,
-               session)
+               session),
+       showing_error_(false)
 {
        connect(&session_, SIGNAL(progress_updated()),
                this, SLOT(on_progress_updated()));
@@ -79,6 +80,8 @@ void StoreProgress::run()
 
 void StoreProgress::show_error()
 {
+       showing_error_ = true;
+
        qDebug() << "Error trying to save:" << session_.error();
 
        QMessageBox msg(parentWidget());
@@ -109,9 +112,8 @@ void StoreProgress::on_progress_updated()
                setMaximum(p.second);
        } else {
                const QString err = session_.error();
-               if (!err.isEmpty())
+               if (!err.isEmpty() && !showing_error_)
                        show_error();
-               close();
        }
 }
 
index fd3558993ced162e12f0505c2f3ab0abd8ee4796..730a9e423d9a51aec37d2b9177106288202770fe 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef PULSEVIEW_PV_DIALOGS_STOREPROGRESS_HPP
 #define PULSEVIEW_PV_DIALOGS_STOREPROGRESS_HPP
 
+#include <atomic>
 #include <memory>
 #include <set>
 
@@ -27,6 +28,7 @@
 
 #include <pv/storesession.hpp>
 
+using std::atomic;
 using std::map;
 using std::pair;
 using std::shared_ptr;
@@ -63,6 +65,7 @@ private Q_SLOTS:
 
 private:
        pv::StoreSession session_;
+       atomic<bool> showing_error_;
 };
 
 }  // namespace dialogs