Commit 0d16e7d0 authored by Elvis Angelaccio's avatar Elvis Angelaccio

Fix crash with blocking Open dialog

`QDialog::exec()` is bad and should not be used unless strictly necessary.
The exec() call is blocking and anything can happen before it returns to the caller.

The old workaround is to use a `QPointer` to guard the dialog.
Yet there is a crash when calling `QCoreApplication::quit()` via dbus while the dialog is open.

The proper fix is to call the dialog in a non-blocking way. Nowadays this is trivial thanks to C++11 lambdas.

Differential Revision: D1786
parent f73b4fba
......@@ -223,16 +223,20 @@ void MainWindow::openArchive()
Q_ASSERT(iface);
Q_UNUSED(iface);
QPointer<QFileDialog> dlg = new QFileDialog(this, i18nc("to open an archive", "Open Archive"));
auto dlg = new QFileDialog(this, i18nc("to open an archive", "Open Archive"));
dlg->setMimeTypeFilters(Kerfuffle::supportedMimeTypes());
dlg->setFileMode(QFileDialog::ExistingFile);
dlg->setAcceptMode(QFileDialog::AcceptOpen);
if (dlg->exec() == QDialog::Accepted) {
openUrl(dlg->selectedUrls().first());
}
delete dlg;
connect(dlg, &QDialog::finished, this, [this, dlg](int result) {
if (result == QDialog::Accepted) {
openUrl(dlg->selectedUrls().first());
}
dlg->deleteLater();
});
dlg->open();
}
void MainWindow::openUrl(const QUrl& url)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment