0

所以我用 Qt Creator 创建了一个 ui 文件,其中有一个 QPushButton。只是为了测试目的,我想弹出一个 QMessageDialog 说你好!在主窗口类中打开 ui 后,我将 ui 中的按钮连接到 def hello(self):

myWidget.helloButton.clicked.connect(self.hello)

然后稍后

def hello(self):
    QtGui.QMessageBox.question(self,'Message',"hello!",QtGui.QMessageBox.Ok)

弹出消息说“你好!” 在消息对话框中单击“确定”后,整个 python 程序退出,有效地使主窗口 GUI 崩溃

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

提前致谢。

编辑:只要我点击“确定”就会发生这种情况

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
4

1 回答 1

0

QDialog将from的父级更改为selfQtGui.QApplication.activeWindow()我有用。

于 2013-07-09T22:07:12.867 回答