From 67ae37d614b3afd9b9a54493fd496a4ea86aa2e9 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Sun, 7 Jun 2020 22:01:30 +0200 Subject: Use QEventLoop instead of manually spinning calling ProcessEvents in a while with a sleep. --- src/mainwindow.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c3a19bf4..fc766af6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2129,11 +2129,20 @@ void MainWindow::activateProxy(bool activate) busyDialog.setWindowFlags(busyDialog.windowFlags() & ~Qt::WindowContextHelpButtonHint); busyDialog.setWindowModality(Qt::WindowModal); busyDialog.show(); - QFuture future = QtConcurrent::run(MainWindow::setupNetworkProxy, activate); - while (!future.isFinished()) { - QCoreApplication::processEvents(); - ::Sleep(100); - } + + QFutureWatcher futureWatcher; + QEventLoop loop; + connect(&futureWatcher, &QFutureWatcher::finished, + &loop, &QEventLoop::quit, + Qt::QueuedConnection); + + futureWatcher.setFuture( + QtConcurrent::run(MainWindow::setupNetworkProxy, activate) + ); + + // wait for setupNetworkProxy while keeping ui responsive + loop.exec(); + busyDialog.hide(); } -- cgit v1.3.1