I am writing a program (PyQt5) helping my coworker to process data. I have a button call "newSession", which supposedly should start a new instance of the program (main window) and operates independently.
The problem I want to avoid: in case one main window crashes, it will crash all the existing main windows. (which it does right now)
Here is simplified version, with only two buttons:
import sys
from PyQt5 import QtWidgets, QtCore
instanceList = []
class newWindow(QtWidgets.QWidget):
def __init__(self) -> None:
super().__init__()
self.idx = 0
self.setTitle()
self.setGeometry(400, 100, 500, 80)
btn1 = QtWidgets.QPushButton(self, text='New session')
btn2 = QtWidgets.QPushButton(self, text='Crash it!')
LO = QtWidgets.QVBoxLayout(self)
LO.addWidget(btn1)
LO.addWidget(btn2)
self.setLayout(LO)
btn1.clicked.connect(self.addWindow)
btn2.clicked.connect(self.crashIt)
def setTitle(self):
self.setWindowTitle('Window {0}'.format(self.idx))
def addWindow(self):
w = newWindow()
w.move(self.pos() + QtCore.QPoint(60, 60))
w.idx = self.idx + 1
w.setTitle()
instanceList.append(w)
w.show()
def crashIt(self):
a.b = 40
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = newWindow()
instanceList.append(window)
window.show()
sys.exit(app.exec_())