Bug 480491

Summary: Warn about QFutureWatcher::connect: connecting after calling setFuture().
Product: [Developer tools] clazy Reporter: Roman <dismine>
Component: generalAssignee: Unassigned bugs mailing-list <unassigned-bugs>
Status: REPORTED ---    
Severity: normal CC: smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Roman 2024-01-29 14:30:16 UTC
Hi.
Is there possible to catch with clazy this warning: QFutureWatcher::connect: connecting after calling setFuture() is likely to produce race? This is probably something new, since i never previously received such a warning. Here is URL to Qt's code. https://github.com/openwebos/qt/blob/92fde5feca3d792dfd775348ca59127204ab4ac0/src/corelib/concurrent/qfuturewatcher.cpp#L367

Here is an example of code that should trigger the warning.

MyClass myObject;
// Start the computation.
QFuture<int> future = QtConcurrent::run(...);
QFutureWatcher<int> watcher;
watcher.setFuture(future);
connect(&watcher, &QFutureWatcher<int>::finished, &myObject, &MyClass::handleFinished);

According to documentation, correct code should look like this:

MyClass myObject;
QFutureWatcher<int> watcher;
connect(&watcher, &QFutureWatcher<int>::finished, &myObject, &MyClass::handleFinished);

// Start the computation.
QFuture<int> future = QtConcurrent::run(...);
watcher.setFuture(future);

Clazy 1.11