Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PySide Qt Creator消息对话框退出_Python_Qt Creator_Pyside - Fatal编程技术网

Python PySide Qt Creator消息对话框退出

Python PySide Qt Creator消息对话框退出,python,qt-creator,pyside,Python,Qt Creator,Pyside,因此,我用QtCreator创建了一个ui文件,其中包括一个QPushButton。出于测试目的,我想弹出一个QMessageDialog,它说hello!在主窗口类中打开ui后,我将该按钮从ui连接到def hello(self): 后来 def hello(self): QtGui.QMessageBox.question(self,'Message',"hello!",QtGui.QMessageBox.Ok) 当我在消息对话框中单击“ok”后,会弹出一条消息说“hello!”,

因此,我用QtCreator创建了一个ui文件,其中包括一个QPushButton。出于测试目的,我想弹出一个QMessageDialog,它说hello!在主窗口类中打开ui后,我将该按钮从ui连接到def hello(self):

后来

def hello(self):
    QtGui.QMessageBox.question(self,'Message',"hello!",QtGui.QMessageBox.Ok)
当我在消息对话框中单击“ok”后,会弹出一条消息说“hello!”,整个python程序退出,从而导致主窗口GUI崩溃

当我不使用UI文件时,这并没有发生在我身上。有人知道为什么会这样吗

提前谢谢

编辑:我一单击“确定”就会发生这种情况

回溯(最近一次呼叫最后一次):
文件“C:\Users\George\Desktop\loadui..py”,第25行,在
main()
文件“C:\Users\George\Desktop\loadui..py”,第23行,主目录
sys.exit(app.exec_())
系统出口:0

QDialog
的父级从
self
更改为
QtGui.QApplication.activeWindow()
对我很有效。

你能说得具体一点吗?是否显示了任何错误消息?好的……那么您可以发布您的
main
?所以我们可以试着给你一个正确的解释…我想出来了,谢谢,我把UI改成了wdiget,然后在主窗口中有一个QMainWindow,并使用setCentralWidgetSo,问题出在哪里
app.exec(
返回0,对吗?放置一个
sys.exit
可能不是最好的主意,因为它告诉Python退出,你不觉得吗?pyside上的所有教程都有,我以前没有遇到过任何问题
def hello(self):
    QtGui.QMessageBox.question(self,'Message',"hello!",QtGui.QMessageBox.Ok)
Traceback (most recent call last):
File "C:\Users\George\Desktop\loadui..py", line 25, in <module>
main()
File "C:\Users\George\Desktop\loadui..py", line 23, in main
sys.exit(app.exec_())
SystemExit: 0