[PyQt] Subclassing QObject and overloading __setattr__

Julien Richard-Foy julien.rf at no-log.org
Sat Jan 26 20:56:11 GMT 2008


Here is the content of Test.py :

class PyQtObject:
  def __init__(self):
    pass
  def __setattr__(self, name, value):
    self.__dict__[name] = value
    print self.__dict__

class MyPyQtObject (PyQtObject):
  def __init__(self):
    PyQtObject.__init__(self)
    self.attr = "value"

i = MyPyQtObject()
i.attr2 = "value2"

When I execute this script, I get this (expected) output :
$ python Test.py
{'attr': 'value'}
{'attr2': 'value2', 'attr': 'value'}


And now if I declare PyQtObject as a child class from QtCore.QObject as 
there :

class PyQtObject (QtCore.QObject):
  def __init__(self):
    QtCore.QObject.__init__(self)
  def __setattr__(self, name, value):
    self.__dict__[name] = value
    print self.__dict__

Here is what I get :
$ python Test.py
{}
{}

Is this the expected behavior ? Why is __dict__ still empty ?
Julien Richard-Foy



More information about the PyQt mailing list