Bug 385475

Summary: Warn on broken Qt autoconnected slots
Product: [Developer tools] clazy Reporter: Nyall Dawson <nyall.dawson>
Component: generalAssignee: Sergio Martins <smartins>
Status: RESOLVED INTENTIONAL    
Severity: wishlist CC: eric.lemanissier, smartins
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: All   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Nyall Dawson 2017-10-07 22:37:22 UTC
I'm working on a large codebase with lots of legacy code, and lots of the older code relied heavily on autoconnect Qt slots ("on_buttonDoSomething_clicked()").

These are extremely fragile and make refactoring code hard. I'd love to see a clazy warning for suspected auto connecting slots which are broken, due to missing/renamed widgets.
Comment 1 Sergio Martins 2017-10-08 10:42:29 UTC
Any suggestion on how to implement it ?

I suppose clazy needs to look inside the generated ui file and check for matching object names.
Comment 2 Nyall Dawson 2017-10-08 22:32:21 UTC
I'd do it in a much cruder way - look for slots which match the regex "on_(.+)_(.+)", where the first group doesn't match a QObject member or the second group doesn't match a signal for the type of that member.

Then we'd catch both errors in the member name AND in the signal name.
Comment 3 eric.lemanissier 2017-10-16 09:09:49 UTC
(In reply to Nyall Dawson from comment #2)
> I'd do it in a much cruder way - look for slots which match the regex
> "on_(.+)_(.+)", where the first group doesn't match a QObject member or the
> second group doesn't match a signal for the type of that member.
> 
> Then we'd catch both errors in the member name AND in the signal name.

Matching the first group with QObject member won't work in a lot of cases, as  the member can actually be a member of the ui member, depending on qt creator's Qt Class Generation setting.
Comment 4 Sergio Martins 2017-12-15 17:01:02 UTC
clazy should warn for all auto connected slots, as it's a very awful feature, regardless if they are broken or working.

That's implemented in #385476 (connect-by-name)