[PyKDE] How to detect if an object has been deleted

Daniel dmiller at tcwcomputers.com
Mon Sep 18 13:40:09 BST 2006


Is there a documented way to detect if the underlying object has been deleted?
Here's a short example that works, but it feels a bit dirty:

def is_deleted(obj):
     try:
         obj.name
     except RunTimeError, ex:
         if str(ex) == "underlying C/C++ object has been deleted":
             return True
         raise
     return False

There are obvious problems with this solution:

- it depends on the exception message
- it depends on an unrelated interface to produce the error (i.e. "name" must be
a non-overridden member on the underlying object)

Is there a supported way to find out if an object has been deleted?  
Thanks.

~ Daniel




More information about the PyQt mailing list