Python:Pickle与Qt(PyQT)
找出为什么在 MyClass() 里把 Qt 对象作为属性会导致两页的崩溃日志,真是件有趣的事情。还有,怎么才能避免这种情况:
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" ) )
1 个回答
7
来自文档的内容:
以下这些PyQt4类可以被“序列化”。
QByteArray QChar QColor QDate QDateTime QKeySequence QLatin1Char QLatin1String QLine QLineF QMatrix QPoint QPointF QPolygon QRect QRectF QSize QSizeF QString QTime
另外,所有命名的枚举(比如QtCore.Qt.Key)也可以被“序列化”。