Python:Pickle和Qt(PyQT) [英] Python: Pickle and Qt (PyQT)

查看:111
本文介绍了Python:Pickle和Qt(PyQT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找出为什么将Qt对象的实例作为MyClass()的属性会导致两页崩溃日志非常有趣.以及如何避免它:

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" ) )

推荐答案

来自 docs :

可能会腌制以下PyQt4类.

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

还可以对所有命名的枚举(例如QtCore.Qt.Key)进行腌制.

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

这篇关于Python:Pickle和Qt(PyQT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆