debugging一个pyQT4应用程序?

我有一个相当简单的应用程序与pyqt4构build。 我想debugging连接到我的应用程序中的button之一的function之一。 但是,当我做到以下几点

python -m pdb app.pyw > break app.pyw:55 # This is where the signal handling function starts. 

事情并不像我希望的那样工作。 debugging器进入一个打印出QCoreApplication::exec: The event loop is already running的无限循环,而不是打破了我设置断点的function, QCoreApplication::exec: The event loop is already running ,我无法input任何东西。 有一个更好的方法吗?

你需要调用QtCore.pyqtRemoveInputHook 。 我把它包装在我自己的set_trace版本中:

 def debug_trace(): '''Set a tracepoint in the Python debugger that works with Qt''' from PyQt4.QtCore import pyqtRemoveInputHook # Or for Qt5 #from PyQt5.QtCore import pyqtRemoveInputHook from pdb import set_trace pyqtRemoveInputHook() set_trace() 

当你完成debugging的时候,你可以调用QtCore.pyqtRestoreInputHook() ,当你还在pdb中时,可能是最好的,然后在你敲回车之后,控制台发送垃圾邮件,继续打“c”(继续)应用程序恢复正常。 (由于某种原因,我不得不多次点击'c',它不停地回到pdb中,但是经过几次后,它恢复正常)

有关更多信息Google“pyqtRemoveInputHook pdb”。 (真的很明显不是吗?

我不得不在跟踪点使用“下一个”命令来首先获取该函数。 为此,我对mgrandi的代码进行了修改:

 def pyqt_set_trace(): '''Set a tracepoint in the Python debugger that works with Qt''' from PyQt4.QtCore import pyqtRemoveInputHook import pdb import sys pyqtRemoveInputHook() # set up the debugger debugger = pdb.Pdb() debugger.reset() # custom next to get outside of function scope debugger.do_next(None) # run the next command users_frame = sys._getframe().f_back # frame where the user invoked `pyqt_set_trace()` debugger.interaction(users_frame, None) 

这对我有效。 我从这里find了解决scheme: Python(pdb) – 排队要执行的命令