Reprojected

A warped look at spatial...

Debugging QGIS Plugins...

Well, the title might better read “debugging PyQt applications…”, but much of my PyQt foo happens when developing QGIS plugins. In general I am old school… emacs and gdb are my friends. When it comes to developing in PyQt there is one life saving code snip that will make your life much easier:

from PyQt4 import QtCore
import pdb
...
QtCore.pyqtRemoveInputHook()
pdb.set_trace()

This not only sets a trace (breakpoint) in your code, but it stops the PyQt event loop. The call to pyqtRemoveInputHook() is a tasty little tidbit in PyQt to allow for this “stop it in it’s tracks” behavior. This is a must have for debugging PyQGIS or Python based plugins.

Once you are in pdb, you are set to go with interactive debugging:

--Return--
> /home/aaronr/.qgis/python/plugins/refmap/refmap.py(101)__init__()->None
-> pdb.set_trace()
(Pdb) bt
<string>(1)<module>()
/home/aaronr/.qgis/python/plugins/refmap/refmap.py(144)initGui()
-> self.refmap_gui = ReferenceMapWindow(self.iface,flags,self)
> /home/aaronr/.qgis/python/plugins/refmap/refmap.py(101)__init__()->None
-> pdb.set_trace()
(Pdb) print self
<refmap.refmap.ReferenceMapWindow object at 0x8cc6c2c>
(Pdb) print self.iface.mainWindow().windowTitle()
Quantum GIS - 1.1.0-Unstable-trunk
(Pdb)

Happy debugging!!!