[PyQt] Pickling Problems
Phil Thompson
phil at riverbankcomputing.com
Sat Jan 2 12:05:08 GMT 2010
On Thu, 31 Dec 2009 22:57:05 -0800, Karthik Tharavaad
<karthiktharavaad at gmail.com> wrote:
> 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:
>
> from PyQt4.QtCore import *
>
> class Foo( QObject ):
>
> def __init__(self,msg="hello",parent=None):
> super(Foo,self).__init__(parent)
> self.msg = msg
>
> def __getstate__(self):
> return self.msg
>
> def __setstate__(self,state):
> self.msg = state
>
>
> if __name__ == "__main__":
> import pickle
> foo = Foo("bar")
> foos = pickle.dumps(foo)
> del foo
> bar = pickle.loads( foos )
> print( bar.msg )
>
> Attempting to run this program crashes Python
> I'm running windows 7 and lattest version of PyQt and Qt
There is a bug in the error handling (fixed in tonight's SIP snapshot).
You need to use pickle protocol 2.
Phil
More information about the PyQt
mailing list