From a0c1b6a512895ec4a1f65016f893635c26c2a7b5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 29 Jan 2024 16:33:24 +0200 Subject: [PATCH] QFutureWatcher::connect: connecting after calling setFuture() is likely to produce race. --- src/app/tape/mapplication.cpp | 4 ++-- src/app/valentina/mainwindowsnogui.cpp | 2 +- src/libs/vlayout/vposition.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index fd50d48cd..bfc826d99 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -829,10 +829,10 @@ void MApplication::RepopulateMeasurementsDatabase(const QString &path) Q_UNUSED(path) if (m_knownMeasurementsDatabase != nullptr) { - m_knownMeasurementsRepopulateWatcher->setFuture( - QtConcurrent::run([this]() { m_knownMeasurementsDatabase->PopulateMeasurementsDatabase(); })); QObject::connect(m_knownMeasurementsRepopulateWatcher, &QFutureWatcher::finished, this, &MApplication::SyncKnownMeasurements); + m_knownMeasurementsRepopulateWatcher->setFuture( + QtConcurrent::run([this]() { m_knownMeasurementsDatabase->PopulateMeasurementsDatabase(); })); } } diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 9adc1981b..9b187303b 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -284,10 +284,10 @@ auto MainWindowsNoGUI::GenerateLayout(VLayoutGenerator &lGenerator) -> bool { QEventLoop wait; QFutureWatcher fw; + QObject::connect(&fw, &QFutureWatcher::finished, &wait, &QEventLoop::quit); fw.setFuture( QtConcurrent::run([&lGenerator, timer, nestingState]() { lGenerator.Generate(timer, lGenerator.GetNestingTimeMSecs(), nestingState); })); - QObject::connect(&fw, &QFutureWatcher::finished, &wait, &QEventLoop::quit); wait.exec(); } diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index 2babe3b88..8e357465e 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -235,10 +235,10 @@ auto VPosition::ArrangeDetail(const VPositionData &data, std::atomic_bool *stop, return position.getBestResult(); }; - watcher.setFuture(QtConcurrent::mapped(jobs, Nest)); - QEventLoop wait; QObject::connect(&watcher, &QFutureWatcher::finished, &wait, &QEventLoop::quit); + + watcher.setFuture(QtConcurrent::mapped(jobs, Nest)); wait.exec(); if (stop->load())