Skip to content

Commit

Permalink
Don't start separate event loop for QFileDialog
Browse files Browse the repository at this point in the history
It conflicts with QMenu on Qt6 that causes the crash.

PR #16158.
  • Loading branch information
glassez committed Jan 22, 2022
1 parent f0ee6ab commit 5ac8582
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/gui/transferlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,35 @@ QVector<BitTorrent::Torrent *> TransferListWidget::getVisibleTorrents() const
void TransferListWidget::setSelectedTorrentsLocation()
{
const QVector<BitTorrent::Torrent *> torrents = getSelectedTorrents();
if (torrents.isEmpty()) return;
if (torrents.isEmpty())
return;

const QString oldLocation = torrents[0]->savePath();
const QString newLocation = QFileDialog::getExistingDirectory(this, tr("Choose save path"), oldLocation,
(QFileDialog::DontConfirmOverwrite | QFileDialog::ShowDirsOnly | QFileDialog::HideNameFilterDetails));
if (newLocation.isEmpty() || !QDir(newLocation).exists()) return;

// Actually move storage
for (BitTorrent::Torrent *const torrent : torrents)
auto fileDialog = new QFileDialog(this, tr("Choose save path"), oldLocation);
fileDialog->setAttribute(Qt::WA_DeleteOnClose);
fileDialog->setFileMode(QFileDialog::Directory);
fileDialog->setModal(true);
fileDialog->setOptions(QFileDialog::DontConfirmOverwrite | QFileDialog::ShowDirsOnly | QFileDialog::HideNameFilterDetails);
connect(fileDialog, &QDialog::accepted, this, [this, fileDialog]()
{
torrent->setAutoTMMEnabled(false);
torrent->setSavePath(Utils::Fs::expandPathAbs(newLocation));
}
const QVector<BitTorrent::Torrent *> torrents = getSelectedTorrents();
if (torrents.isEmpty())
return;

const QString newLocation = fileDialog->selectedFiles().constFirst();
if (newLocation.isEmpty() || !QDir(newLocation).exists())
return;

// Actually move storage
for (BitTorrent::Torrent *const torrent : torrents)
{
torrent->setAutoTMMEnabled(false);
torrent->setSavePath(newLocation);
}
});

fileDialog->show();
}

void TransferListWidget::pauseAllTorrents()
Expand Down

0 comments on commit 5ac8582

Please sign in to comment.