退出PyQT应用程序时出现分段错误

时间:2016-11-30 06:02:21

标签: python pyqt pyqtgraph

首先,我已经尽力在这里和其他地方找到解决这个问题的方法,我对这个问题有一个大概的了解,但我不清楚如何解决它。

基本问题是当我通过按下标准" x"来关闭我的应用程序时出现分段错误。按钮。

最重要的细节(我认为)是我使用的是MacOS Sierra,python 3.5.2和pyqt5。

我正在构建的应用程序非常松散地基于另一个项目(Dioptas),这是一个相对成熟的项目。我或多或少开始了。

当我关闭窗口时,终端按照MainController.close_event()中的指示打印出来:

> here
> closed
> accepted
> Segmentation fault: 11

我在网上尝试了很多建议,我很确定这是因为python没有关闭所有窗口(可能是由于它们被关闭的顺序 - QApplication.CloseAllWindows()说它们已关闭以一种随机的顺序,一件事)。如果有人有建议或解决方案我会非常感激。

以下是我的代码:

import sys
import pyqtgraph as pg
import numpy as np
from PIL import Image
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

class MainController(QWidget):
    def __init__(self):
        super().__init__
        self.start()
        self.create_signals()

    def start(self):
        self.widget = MainWidget()
        self.widget.show()

    def create_signals(self):
        self.widget.closeEvent = self.close_event

    def close_event(self, ev):
        print("here")
        QApplication.closeAllWindows()
        print("closed")
        ev.accept()

class MainWidget(QWidget):
    def __init__(self, *args, **kwargs):
        super(MainWidget, self).__init__(*args, **kwargs)
        self.layout = QHBoxLayout()
        self.layout.setContentsMargins(2, 2, 2, 2)
        self.layout.setSpacing(6)

        self.stepFilterDisplayWidget = StepFilterDisplayWidget()
        self.stepFilterControlWidget = StepFilterControlWidget()
        self.layout.addWidget(self.stepFilterDisplayWidget)
        self.layout.addWidget(self.stepFilterControlWidget)
        self.setLayout(self.layout)
        self.setGeometry(100,100,1000,700)

class StepFilterDisplayWidget(QWidget):
    def __init__(self, *args, **kwargs):
        super(StepFilterDisplayWidget,self).__init__(*args,**kwargs)

        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        self.plot = pg.ImageView()
        self.layout.addWidget(self.plot)

        self.button = QPushButton("Plot", self)
        self.button.clicked.connect(self.showImage)

        self.layout.addWidget(self.button)

    def showImage(self):
        im = Image.open('S_15a_crop.tif')
        self.data = np.array(im)
        self.plot.setImage(self.data)


class StepFilterControlWidget(QWidget):
    def __init__(self, *args, **kwargs):
        super(StepFilterControlWidget, self).__init__(*args, **kwargs)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    controller = MainController()
    app.exec_()
    del app

1 个答案:

答案 0 :(得分:2)

问题在于pyqtgraph(使用PyQt4)和PyQt5导入。尝试使用pyqtgraph属于PyQt4导入的PyQt4。这会触发分段错误。