PySide Qt Creator message dialog exit
So I created a ui file with Qt Creator that has, among other things, a QPushButton. Just for testing purposes I want to pop up a QMessageDialog that says hello! After opening the ui in the main window class, I connect the button from the ui to the def hello(self):
myWidget.helloButton.clicked.connect(self.hello)
then later on
def hello(self):
QtGui.QMessageBox.question(self,'Message',"hello!",QtGui.QMessageBox.Ok)
The message pops up saying "hello!" and after I click "ok" inside the message dialog, the entire python program exits, effectively crashing the main window GUI
This did not happen to me when I was not using the UI file. Does anyone know why this is happening?
Thanks in advance.
edit: This happens as soon as I click "ok"
Traceback (most recent call last):
File "C:UsersGeorgeDesktoploadui..py", line 25, in <module>
main()
File "C:UsersGeorgeDesktoploadui..py", line 23, in main
sys.exit(app.exec_())
SystemExit: 0
将QDialog
的父对象从self
更改为QtGui.QApplication.activeWindow()
为我工作。
上一篇: 在Python中清除终端