Pickle.load in pyqt5

2019-08-02 08:15发布

问题:

I'm having trouble with a MainWindow using pickle to load serialized data.
Just a simple MainWindow

class MainWindow(QtWidgets.QMainWindow, UI.MainUI.Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.action_save.triggered.connect(self.save)
        self.action_load.triggered.connect(self.load)

    def save(self):
        with open("Save", "wb") as f:
        pickle.dump(self.test, f)

    def load(self):
        with open("Save", "rb") as f:
        self.test = pickle.load(f)

    def go(self):
        self.test = Test(14)

class Test():
    def __init__(self, a):
        self.a = a

I can't get the save to happen as a runtime error occurs even though I do call the super of MainWindow:

self.test = pickle.load(f)
RuntimeError: super-class __init__() of type MainWindow was never called