From 0ad56591fd9581aa9195f854ac3fc1b40d5b1802 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sat, 6 Jun 2020 13:40:38 +0200 Subject: Fix order of operations to avoid deadlock with event loop. --- src/installationmanager.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 7f4ad864..9d64a6f3 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -186,25 +186,28 @@ bool InstallationManager::extractFiles(QString extractPath, QString title, bool auto start = std::chrono::system_clock::now(); + // Future watcher to exit the loop: + QFutureWatcher futureWatcher; + + QEventLoop loop(this); + connect( + &futureWatcher, &QFutureWatcher::finished, + &loop, &QEventLoop::quit, + Qt::QueuedConnection); + // unpack only the files we need for the installer - QFuture future = QtConcurrent::run([&]() -> bool { + futureWatcher.setFuture(QtConcurrent::run([&]() -> bool { return m_ArchiveHandler->extract( extractPath.toStdWString(), progressCallback, showFilenames ? fileChangeCallback : nullptr, errorCallback ); - }); - - // Future watcher to exit the loop: - QFutureWatcher futureWatcher; - futureWatcher.setFuture(future); - - QEventLoop loop(this); - connect(&futureWatcher, &QFutureWatcher::finished, &loop, &QEventLoop::quit); + })); // Wait for future to complete: loop.exec(); + auto future = futureWatcher.future(); // Check the result: if (!future.result()) { -- cgit v1.3.1