Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Pickle and Qt (PyQT)

It would be quite entertaining to find why having an instance of Qt object as a MyClass()'s attribute causes a two pages crash log. And how to avoid it:

import sys, os, pickle
from PyQt4 import QtGui

class MyClass(object):
    def __init__(self):
        self.myQtWidget=QtGui.QPushButton() 
        pass 

app = QtGui.QApplication(sys.argv)
myInstance=MyClass()
pickle.dump( myInstance, open( "save.mydata", "wb" ) )
like image 719
alphanumeric Avatar asked Apr 06 '14 04:04

alphanumeric


1 Answers

From the docs:

The following PyQt4 classes may be pickled.

QByteArray
QChar
QColor
QDate
QDateTime
QKeySequence
QLatin1Char
QLatin1String
QLine
QLineF
QMatrix
QPoint
QPointF
QPolygon
QRect
QRectF
QSize
QSizeF
QString
QTime

Also all named enums (QtCore.Qt.Key for example) may be pickled.

like image 158
ekhumoro Avatar answered Nov 14 '22 22:11

ekhumoro