Slots & Signals - How can I avoid losing track of the control structure?
-
Hi all,
Beginner Qt (PySide6) developer here, I hope my question is not too silly.
When I develop a Qt app with multiple components, I tend to lose track of the slots and signals, when they are triggered and where they get consumed. I think there are two aspects that make it more difficult for me than in my previous coding projects:
-
I find it cumbersome to identify the slots associated with a signal and vice versa. For "normal" functions or methods, my IDE (vscode) supports me very well in finding their references, but for slots/signals I resort to a simple full-text search in the codebase.
-
Also, my components seem to be more interconnected than other classes/modules I write. E.g. circular dependencies between modules are prohibited in Python, but with Qt it sometimes seems hard to avoid them. Perhaps this is already one of my antipatterns?
Do you have any recommendations (or resources like blog posts, docs, etc.) that can help a beginner like me avoid a mess and keep Qt code structured? If they are Python centered, even better!
Thanks a lot!
-
-
Hi,
If you have circular dependencies in your Qt code, it likely means that you are doing something wrong. From experience, I would say that your objects are knowing way too much about each other. A class that has signals shall not care nor know who is consuming its signals. That's not its role.
For your signal slot tracking issue, are you annotating them properly ?
-
@dynobo Starting a reply with " I am in same boat" is a cliche and it does not help (you) .
I have half a dozen "objects" passing messages - both directions and using "emit" and "connect".I am using GUI / tab to keep track and of course QDebug.
It is not ideal ....I was going to add old fashioned flowchart ( text or GUI ) , but got sidetracked....