I've been trying to implement pickling support on some of my own classes which inherits QObject, however, I always crash Python when I attempt to run the application. The simple test program below illustrates my problem:<div>
<br></div><div><div>from PyQt4.QtCore import *</div><div><br></div><div>class Foo( QObject ):</div><div> </div><div> def __init__(self,msg="hello",parent=None):</div><div> super(Foo,self).__init__(parent)</div>
<div> self.msg = msg</div><div> </div><div> def __getstate__(self):</div><div> return self.msg</div><div> </div><div> def __setstate__(self,state):</div><div> self.msg = state</div><div>
</div><div> </div><div>if __name__ == "__main__":</div><div> import pickle</div><div> foo = Foo("bar")</div><div> foos = pickle.dumps(foo)</div><div> del foo</div><div> bar = pickle.loads( foos )</div>
<div> print( bar.msg )</div><div> </div><div>Attempting to run this program crashes Python </div><div>I'm running windows 7 and lattest version of PyQt and Qt</div><div><br></div></div>