在 pyqt 中使用 sys.exit() 和 app.exec_ [英] Using sys.exit() with app.exec_ in pyqt
问题描述
谁能解释使用 sys.exit(app.exec_())
而不是更简单的 app.exec_()
在 PyQt 中启动 GUI 的相对优点?
Can anyone explain the relative merits of using sys.exit(app.exec_())
rather than the simpler app.exec_()
to start a GUI in PyQt?
我是 PyQt 的新手,并且看过这两个示例.
I am new to PyQt and have seen both examples.
推荐答案
当 Unix 风格的应用程序退出时,他们返回一个数字给它们的父进程,称为状态代码"或退出状态".0
用于表示成功;任何非零都是失败的.(有一些尝试标准化错误代码的含义,但通常仍由每个程序决定.)
When Unix-style applications exit, they return a number to their parent process called a 'status code' or 'exit status'. 0
is used to indicate success; anything non-zero is a failure. (There's been some attempt to standardise the meaning of error codes, but it's still generally left up to each program.)
app.exec_()
运行你的主循环, 退出时返回状态码.sys.exit(n)
退出您的应用程序并将 n
返回到父进程(通常是您的 shell).所以区别在于,当您的程序退出时,较长的版本会传递状态代码.最好使用 sys.exit(app.exec_())
因为这样系统的其他部分可以检测到您的程序何时因错误退出.
app.exec_()
runs your main loop, and returns a status code when it exits. sys.exit(n)
quits your application and returns n
to the parent process (normally your shell). So the difference is, the longer version passes on the status code when your program exits. It's better to use sys.exit(app.exec_())
because then other parts of the system can detect when your program exited due to an error.
这篇关于在 pyqt 中使用 sys.exit() 和 app.exec_的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!