On the PySide signals and slots page it says: "Signals are runtime objects owned by instances, they are not class attributes". Apparently the QObject constructor looks in the class attributes for Signals and copies them to the object instance. This is confirmed by my test program.
from PySide import QtCore
class Klass(QtCore.QObject):
lst = []
sig = QtCore.Signal(str)
def main():
obj1 = Klass()
obj2 = Klass()
print "id: obj1.lst = {}, obj1.sig = {}".format(id(obj1.lst), id(obj1.sig))
print "id: obj2.lst = {}, obj2.sig = {}".format(id(obj2.lst), id(obj2.sig))
print "id: klass.lst = {}, klass.sig = {}".format(id(Klass.lst), id(Klass.sig))
if __name__ == '__main__':
main()
In my output you can see that there are now three signal objects whereas the id of lst-member is the same for both objects and the class.
id: obj1.lst = 4317739344, obj1.sig = 4297560376
id: obj2.lst = 4317739344, obj2.sig = 4297560400
id: klass.lst = 4317739344, klass.sig = 4317851072
Implicitly creating the object attributes is just confusing and therefore bad style (IMHO). Maybe they do have good reasons for this but I don't see them. So my question is: why did they choose this solution instead of just creating the signal as a regular attribute in the constructor?