[PyQt] Catching Qt exceptions in PyQt
Patrick Kennedy
pakattack161 at gmail.com
Sat Sep 8 09:08:41 BST 2007
Howdy! I had a major problem with this myself and after doing some research
I finally found a solution in eventFilters (
http://doc.trolltech.com/4.3/qobject.html#eventFilter
) which is basically the same thing only you don't need to mess with
class wrappers and stuff =]
Here is my example that I used. Pretty simple, and you'll need to adjust it
for your specific problem and you'll need to look at (
http://doc.trolltech.com/4.3/qevent.html) for all the event code. It just
gave me a traceback at the point I verified it errored, in this case when I
clicked the object.
class FilterObject(QtCore.QObject):
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.MouseButtonRelease:
traceback.print_exc()
else:
print event.type()
#Pass the event onto the parent window.
return QtCore.QObject.eventFilter(self, obj, event)
Then you just install the filter, like so, to everything that you suspect
errors:
QObject.installEventFilter(FilterObject)
Later, now that there would be a need for it, I could write up one that
gives you an action instead of a number, but I'm not up for something so
tedious at 0210 =]
On 9/7/07, Claudio A. Quezada R. <claudio.quezada.r at gmail.com> wrote:
>
> Hello, i´ve got the very same trouble several of times, and i tried to
> reimplement notify, but the same exception was thrown over and over
> again.
>
> I changed the code (finding where was the error) and exception didn´t
> appear again. It´s seems easier debug and change the code than
> reimplement QApplication notify, at least for me. Probably silly
> errors (like setItem to a QTableWidget that isn´t enabled, or setText
> on a QTableWidgetItem that don´t exists) are common.
>
> Anyway, if anyone get QApplication notify works, post it at the list.
>
> Cheers,
>
> Claudio
>
> 2007/9/7, Allen Bierbaum <abierbaum at gmail.com>:
> > I don't know what you are doing wrong or what causes this, but I do
> > know that we see it all the time when trying to debug and it makes the
> > entire process very painful. If you find any type of solution that
> > works so you can see the exception that is being thrown, please let me
> > know so we can use it.
> >
> > -Allen
> >
> > On 9/7/07, Dirk Wagener <dwagen at stonethree.com> wrote:
> > > Hi
> > >
> > > I have a piece of code that produces this error:
> > >
> > > "Qt has caught an exception thrown from an event handler. Throwing
> > > exceptions from an event handler is not supported in Qt.
> > > You must reimplement QApplication::notify() and catch all exceptions
> > > there. "
> > >
> > > I implemented my own app class as follows:
> > >
> > > class Application (QtGui.QApplication):
> > > def __init__(self, argv):
> > > QtGui.QApplication.__init__(self, argv)
> > >
> > > def notify(self, obj, evt):
> > > try:
> > > # Call base class notify.
> > > return QtGui.QApplication.notify(self, obj, evt)
> > > except Exception:
> > > print "Unexpected error:",
> > > string.join(traceback.format_exception(*sys.exc_info()))
> > > return False
> > >
> > > My code still produces exactly the same error, so it seems that the
> > > exception is still not caught!
> > > What am I doing wrong here?
> > >
> > > Kind regards
> > > Dirk Wagener
> > > _______________________________________________
> > > PyQt mailing list PyQt at riverbankcomputing.com
> > > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> > >
> > _______________________________________________
> > PyQt mailing list PyQt at riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> >
>
>
> --
> Claudio Quezada Romegialli
> Ingeniero Ambiental
> (02)7321665 - 81466049
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20070908/d54ed01e/attachment.html
More information about the PyQt
mailing list