What are some best practices for debugging Qt signals and slots?

后端 未结 4 1872
青春惊慌失措
青春惊慌失措 2021-02-04 19:27

Debugging signals and slots can be hard, because the debugger does not jump to the slots of a signal when it is emitted. What are some best practices for debugging Qt signals an

4条回答
  •  旧巷少年郎
    2021-02-04 19:40

    Regarding #1, I'll just add another piece of information that I didn't see mentioned above or in the referenced blog post.

    From the documentation on QObject::connect():

    Creates a connection of the given type from the signal in the sender object to the method in the receiver object. Returns true if the connection succeeds; otherwise returns false.

    I prefer asserting the return value of my connection to make sure the connection succeeded, especially because not all Qt programs will have console output. This also leads to more easily maintainable code, as it will catch changes made at a later date to either the signal or the slot, and force the programmer who made the changes to update the connections as well.

提交回复
热议问题