[PyKDE] Exceptions in callbacks

Pete Ware ware at cis.ohio-state.edu
Fri Feb 2 23:01:01 GMT 2001


I'm still wondering how to catch an exception that occurs in a slot.
Supposed I wanted the following exception to print in a dialog box
instead of to the console.  How?

Thanks,
--pete
----------------------------------------------------------------------
#! /bin/env python
#				-*- Python -*-
import sys
import qt

class Test (qt.QFrame):
	def __init__ (self, parent = None, name = ''):
		qt.QFrame.__init__ (self, parent, name)
		top = qt.QPushButton ('Exception', self)
		top.setMinimumSize (top.sizeHint ())
		top.connect (top, qt.SIGNAL ('clicked()'), self.raise_exception)

	def raise_exception (self):
		raise 'An exception.  How can I catch this?'
		
w = None
def test ():
	global w
	app = qt.QApplication (sys.argv)

	w = Test (None, 'Table')
	app.setMainWidget (w)
	w.show ()

	return app

if __name__ == '__main__':
	print 'starting app...',
	app = test ()
	print 'done'
	app.exec_loop ()




More information about the PyQt mailing list