PyQt - system crash when I shift to the third window

-2

I am a beginner of using PyQt. I want to build a simple system with PyQt which can shift to different windows when clicking the button. But the system always crashes when shifting to the third window. And return the mistake like this

****Process finished with exit code -1073740791 (0xC0000409)*****

I have tried to change the type of different windows to make them different with prior one (QDialog→QWidget QWidget→QDialog), but this method didn't make sense.

Hope someone can help me to figure out this problem.

Here is an example code

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

class FirstWindow(QWidget):

    close_signal = pyqtSignal()
    def __init__(self, parent=None):
        super(FirstWindow, self).__init__(parent)
        self.resize(100, 100)
        self.btn = QToolButton(self)
        self.btn.setText("click")

    def closeEvent(self, event):
        self.close_signal.emit()
        self.close()


class SecondWindow(QDialog):
    def __init__(self, parent=None):
        super(SecondWindow, self).__init__(parent)
        self.resize(150, 150)
        self.btn2 = QToolButton(self)
        self.btn2.setText("click")

class ThirdWindow(QDialog):
    def __init__(self, parent=None):
        super(SecondWindow, self).__init__(parent)
        self.resize(200, 200)
        self.setStyleSheet("background: red")

if __name__ == "__main__":
    App = QApplication(sys.argv)
    ex = FirstWindow()
    s = SecondWindow()

    ex.show()
    ex.btn.clicked.connect(s.show)
    s.btn2.clicked.connect(ThirdWindow.show)
    sys.exit(App.exec_())
python
pyqt
pyqt5
asked on Stack Overflow Feb 12, 2018 by Chason Fu • edited Feb 14, 2018 by Skandix

1 Answer

0

you didn't created an instance of your third class, use this adjustment:

App = QApplication(sys.argv)
first = FirstWindow()
second = SecondWindow()
third = ThirdWindow() # this line was added

first.show()
first.btn.clicked.connect(second.show)
second.btn2.clicked.connect(third.show)
sys.exit(App.exec_())

btw: your handle_close is never called

answered on Stack Overflow Feb 14, 2018 by Skandix

User contributions licensed under CC BY-SA 3.0