You can't pickle QObject subclasses, because they are C++ extensions and 
contain internal state and pointers and stuff.
The Qt approach (to follow what they already do on QMainWindow and other 
widgets) is to create a saveState() and restoreState(state) method on your class

class Widget(QtGui.QWidget):

    def saveState(self):
        state = {
            'size': (500,50)
        }
        return state

    def restoreState(self, state):
        size = state.get('size')
        if size:
            self.resize(size)

Then you would pickle the simple object state and later get it back and call 
restoreState() on an instance. I find this approach also useful for loading 
back preferences of your widgets from QSettings on the fly. QSettings allows 
you to serialize any QVariant type though. But I try and avoid it because it 
hard codes "PyQt" or "PySide" to your serialization file. I prefer to pickle it 
first and save it as a string.


On Apr 26, 2013, at 1:48 AM, illunara wrote:

> Hi everybody
> 
> I try to export some data using cPickle, its fine when i try on difference 
> object, but not pyqt. It gave me an error
> 
> # Error: TypeError: file C:\Program 
> Files\Autodesk\Maya2012\bin\python26.zip\copy_reg.py line 71: the sip.wrapper 
> type cannot be instantiated or sub-classed # 
> 
> I'm using xml to export data too, but just curious :D
> 
> Also, i have another favor want to ask , can anyone give me some sample about 
> writing a callback using Python please? :3
> 
> Thanks 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To post to this group, send email to python_inside_maya@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To post to this group, send email to python_inside_maya@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to