Skip to content Skip to sidebar Skip to footer

Python Pyqt Callback Never Runs - How To Debug?

I have a fairly complicated piece of code using PyQt4 and sometimes my signal callbacks simply never run. It seems to be related to where/when I register the callbacks, ie. self.so

Solution 1:

Unfortunately it was a silly mistake as suggested in the comments to the question. It had nothing to do with PyQt or the use of signals. I post what the problem was and how I debugged it in hopes that it still might help somebody.

What the problem was

I was overwriting the object that emitted the signal with a new one (an attempt to reset state), so its signal was not connected to the callback any more.

How it was detected

In the debugger I noticed that the address of a.pp.rr had one value when I connected the signal to it, and when the signal was emitted, it's address was different. Two different objects.

So the code was clean and the use of PyQt signals was correct. Perhaps the lesson learned is to be careful when replacing an instance. Make sure to reconnect all signals to/from the new instance, or create a method in the object to reset it's state (this is what I did) to avoid destroying the original instance.

Other Options

With regards to creating an Minimal, Complete, and Verifiable example as suggested earlier, it is perhaps the most appropriate way to format a question in this forum and a good exercise in identifying the source of problems. Equally valid, and perhaps more appropriate for more obscure and complex problems is through the skillful use of the debugger. If you are coding A to be connected to B and A is not having and impact on B, then it is possible that A is not the same "A" or B is not the same "B" as when the "connection" was made, or the connection was removed at some point. When you are missing something, perhaps you want is to gain more visibility into what is happening.

Post a Comment for "Python Pyqt Callback Never Runs - How To Debug?"