代码之家  ›  专栏  ›  技术社区  ›  Paul Wicks asgeo1

调试pyQT4应用程序?

  •  37
  • Paul Wicks asgeo1  · 技术社区  · 15 年前

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

    QCoreApplication::exec: The event loop is already running 我无法输入任何内容。有更好的方法吗?

    2 回复  |  直到 15 年前
        1
  •  87
  •   Martin Tournoij ravi.zombie    9 年前

    你需要打电话 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()
    

    QtCore.pyqtRestoreInputHook() ,可能最好是在您仍处于pdb状态时,然后在您点击enter键,并且控制台出现垃圾邮件后,继续点击“c”(继续),直到应用程序正常恢复(由于某种原因,我不得不按了几次“c”,它一直返回pdb,但在按了几次后,它恢复正常)

    欲了解更多信息,请点击谷歌“pyqtRemoveInputHook pdb”(真的很明显,不是吗;(P)

        2
  •  4
  •   Community ƒernando Valle    7 年前

    我必须在跟踪点使用一个“next”命令,才能首先跳出该函数。为此,我修改了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)
    

    这对我有用。我从这里找到了解决方案: Python (pdb) - Queueing up commands to execute

        3
  •  0
  •   Phillip M. Feldman    4 年前

    在我的测试中,jamk的解决方案是有效的,而前一个方案虽然简单,但不起作用。