From: Soeren Apel Date: Wed, 24 May 2017 21:50:37 +0000 (+0200) Subject: Fix #895 by adapting to Qt5 and cleaning up properly X-Git-Tag: pulseview-0.4.0~77 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f7449c50675c7e9cc152bb367b3850f3c6310228;p=pulseview.git Fix #895 by adapting to Qt5 and cleaning up properly Relevant Qt commit: https://codereview.qt-project.org/#/c/72637/ "QProgressDialog: don't require setValue(0) to be called." "Fixed by starting the timer in the constructor (most code doesn't reuse progress dialogs, so this fixes the most common case)" This messes us up because we're (ab-)using the dialog in a non-standard way. https://bugreports.qt.io/browse/QTBUG-47042 "QProgressDialog is designed to show itself automatically, based on an internal estimate for the duration of the operation and the minimumDuration property. You never call show() or exec() on it manually. You're also not supposed to keep it around when it's not used. In 5.4, the only way to start the internal duration estimation was to call setValue(0). But we noticed that many people didn't call setValue(0)" Workaround here: https://bugreports.qt.io/browse/QTBUG-47042 "As a workaround I added the line m_progressDlg->reset(); in the main window constructor in order to get the same behavior as in former versions." --- diff --git a/pv/dialogs/storeprogress.cpp b/pv/dialogs/storeprogress.cpp index 09b6b0f4..0d0a222c 100644 --- a/pv/dialogs/storeprogress.cpp +++ b/pv/dialogs/storeprogress.cpp @@ -48,6 +48,19 @@ StoreProgress::StoreProgress(const QString &file_name, this, SLOT(on_progress_updated())); connect(&session_, SIGNAL(store_successful()), &session, SLOT(on_data_saved())); + + // Since we're not setting any progress in case of an error, the dialog + // will pop up after the minimumDuration time has been reached - 4000 ms + // by default. + // We do not want this as it overlaps with the error message box, so we + // set the minimumDuration to 0 so that it only appears when we feed it + // progress data. Then, call reset() to prevent the progress dialog from + // popping up anyway. This would happen in Qt5 because the behavior was + // changed in such a way that the duration timer is started by the + // constructor. We don't want that and reset() stops the timer, so we + // use it. + setMinimumDuration(0); + reset(); } StoreProgress::~StoreProgress() @@ -71,11 +84,17 @@ void StoreProgress::show_error() msg.setStandardButtons(QMessageBox::Ok); msg.setIcon(QMessageBox::Warning); msg.exec(); + + close(); } void StoreProgress::closeEvent(QCloseEvent*) { session_.cancel(); + + // Closing doesn't mean we're going to be destroyed because our parent + // still owns our handle. Make sure this stale instance doesn't hang around. + deleteLater(); } void StoreProgress::on_progress_updated()