在 Python 3 和 PyQt 中使用 QProcess.finished() [英] Using QProcess.finished() in Python 3 and PyQt
本文介绍了在 Python 3 和 PyQt 中使用 QProcess.finished()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 QProcess.finished() 调用不同的 Python3 脚本.
How can I use the QProcess.finished() to call a different Python3 script.
这是我调用的脚本:
#!/usr/bin/python
from PyQt4.QtGui import QApplication
from childcontrolgui import childcontrolgui
def main():
import sys
app = QApplication(sys.argv)
wnd = childcontrolgui()
wnd.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
要调用脚本,我使用此处
def properties(self):
command="python3 ../GUI/main.py"
self.process=QProcess()
self.process.finished.connect(self.onFinished)
self.process.startDetached(command)
def onFinished(self, exitCode, exitStatus):
self.Check_Timer.stop()
self.Logout_Timer.stop()
self.Firstrun=True
self.initControl()
进程开始工作,显示来自 main.py 的窗口,但似乎没有触发完成.当我从 main.py 关闭窗口时什么也没发生
Starting of the process works, the window from main.py is shown, but it seems, finished isn't fired. Nothing happens, when I close the Window from main.py
推荐答案
当你使用startDetached()时你无法得到信号,因为你没有对象.改用普通的 start().
You can't get a signal when you use startDetached() because you have no object. Use ordinary start() instead.
并且不要忘记在控制脚本中启动 QApplication.
And don't forget to start QApplication within control script, too.
class Control(QObject):
def properties(self):
self.process=QProcess()
self.process.finished.connect(self.onFinished)
self.process.start('python3', ['../GUI/main.py'])
def onFinished(self, exitCode, exitStatus):
[...]
if __name__ == '__main__':
app = QApplication(sys.argv)
co = Control()
co.properties()
sys.exit(app.exec_())
这篇关于在 Python 3 和 PyQt 中使用 QProcess.finished()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文