Issue
First, I have tried my best to find a solution to this problem here and other places and I am have a general idea of what the problem is, but it is not clear to me how to solve it.
The basic problem is that I am getting a segmentation fault when I close my app by pressing the standard "x" button.
The most important details (I think) are that I am using MacOS Sierra, python 3.5.2, and pyqt5.
The app I am building is very loosely based on another project (Dioptas), which is a relatively mature project. I am more or less getting started.
When I close the window, the terminal prints out as instructed in MainController.close_event():
> here
> closed
> accepted
> Segmentation fault: 11
I have tried many of the suggestions online and I am fairly sure that this is due to python not closing all of the windows (perhaps due to the order in which they are being closed - QApplication.CloseAllWindows() says they are closed in a random order, for one thing). If anyone has a suggestion or solution I would really appreciate it.
The following is my code:
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
Solution
The problem is about pyqtgraph (which uses PyQt4) and PyQt5 imports. pyqtgraph trying to use something belongs to PyQt4 which was overriden by PyQt5 import. This triggers the segmentation fault.
Answered By - obayhan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.