调试 pyQT4 应用程序? [英] Debugging a pyQT4 app?

查看:34
本文介绍了调试 pyQT4 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 pyqt4 构建的相当简单的应用程序.我想调试连接到我的应用程序中的按钮之一的功能之一.但是,当我执行以下操作时

I have a fairly simple app built with pyqt4. I wanted to debug one of the functions connected to one of the buttons in my app. However, when I do the following

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

事情并不像我希望的那样工作.调试器没有中断我设置断点的函数并让我单步执行,而是进入一个无限循环,打印出 QCoreApplication::exec: The event loop has been running 并且我无法输入任何东西.有没有更好的方法来做到这一点?

things don't quite work like I'd hope. Instead of breaking in the function where I've set the breakpoint and letting me step through it, the debugger enters an infinite loop printing out QCoreApplication::exec: The event loop is already running and I am unable to input anything. Is there a better way to do this?

推荐答案

您需要致电 QtCore.pyqtRemoveInputHook.我将它包装在我自己的 set_trace 版本中:

You need to call QtCore.pyqtRemoveInputHook. I wrap it in my own version of 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()

当你完成调试后,你可以调用QtCore.pyqtRestoreInputHook(),可能最好在你还在pdb的时候,然后在你回车后,控制台垃圾邮件正在发生,保持点击c"(继续),直到应用程序正常恢复.(由于某种原因,我不得不多次点击'c',它一直回到pdb,但在点击几次后它恢复正常)

And when you are done debugging, you can call QtCore.pyqtRestoreInputHook(), probably best when you are still in pdb, and then after you hit enter, and the console spam is happening, keep hitting 'c' (for continue) until the app resumes properly. (I had to hit 'c' several times for some reason, it kept going back into pdb, but after hitting it a few times it resumed normally)

更多信息谷歌pyqtRemoveInputHook pdb".(真的很明显不是吗?;P)

For further info Google "pyqtRemoveInputHook pdb". (Really obvious isn't it? ;P)

这篇关于调试 pyQT4 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆