QFutureWatcher::connect: connecting after calling setFuture() is likely to produce race.

This commit is contained in:
Roman Telezhynskyi 2024-01-29 16:33:24 +02:00
parent 6164120969
commit a0c1b6a512
3 changed files with 5 additions and 5 deletions

View File

@ -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<void>::finished, this,
&MApplication::SyncKnownMeasurements);
m_knownMeasurementsRepopulateWatcher->setFuture(
QtConcurrent::run([this]() { m_knownMeasurementsDatabase->PopulateMeasurementsDatabase(); }));
}
}

View File

@ -284,10 +284,10 @@ auto MainWindowsNoGUI::GenerateLayout(VLayoutGenerator &lGenerator) -> bool
{
QEventLoop wait;
QFutureWatcher<void> fw;
QObject::connect(&fw, &QFutureWatcher<void>::finished, &wait, &QEventLoop::quit);
fw.setFuture(
QtConcurrent::run([&lGenerator, timer, nestingState]()
{ lGenerator.Generate(timer, lGenerator.GetNestingTimeMSecs(), nestingState); }));
QObject::connect(&fw, &QFutureWatcher<void>::finished, &wait, &QEventLoop::quit);
wait.exec();
}

View File

@ -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<VBestSquare>::finished, &wait, &QEventLoop::quit);
watcher.setFuture(QtConcurrent::mapped(jobs, Nest));
wait.exec();
if (stop->load())