Bug 480491 - Warn about QFutureWatcher::connect: connecting after calling setFuture().
Summary: Warn about QFutureWatcher::connect: connecting after calling setFuture().
Status: REPORTED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Unassigned bugs mailing-list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-29 14:30 UTC by Roman
Modified: 2024-01-29 14:30 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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