diff options
| author | Al <26797547+Al12rs@users.noreply.github.com> | 2020-06-08 06:58:16 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-08 06:58:16 -0700 |
| commit | 4e0d47868ab78c58afca0733d3686c7dc3c6a4d9 (patch) | |
| tree | a2dcfe2de16b86bc88bdc99c8d912b8bb16d4807 /src/mainwindow.cpp | |
| parent | ec5a78cefa610df153063c3cbfcc42b36998a542 (diff) | |
| parent | 67ae37d614b3afd9b9a54493fd496a4ea86aa2e9 (diff) | |
Merge pull request #1113 from Al12rs/bettr_wait_on_events
Use QEventLoop instead of manually calling ProcessEvents
Diffstat (limited to 'src/mainwindow.cpp')
| -rw-r--r-- | src/mainwindow.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
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<void> future = QtConcurrent::run(MainWindow::setupNetworkProxy, activate); - while (!future.isFinished()) { - QCoreApplication::processEvents(); - ::Sleep(100); - } + + QFutureWatcher<void> futureWatcher; + QEventLoop loop; + connect(&futureWatcher, &QFutureWatcher<void>::finished, + &loop, &QEventLoop::quit, + Qt::QueuedConnection); + + futureWatcher.setFuture( + QtConcurrent::run(MainWindow::setupNetworkProxy, activate) + ); + + // wait for setupNetworkProxy while keeping ui responsive + loop.exec(); + busyDialog.hide(); } |
