QProcess正常退出
QProcess exit normally
我在 qt 中使用 python,但我找不到在 Qprocess 正常退出时触发信号的方法,根据 Pyqt 文档 finished() 信号可以采用 2 个参数 exitCode 和 exitStatus
这是 Pyqt 文档中关于 finished() 信号的描述
http://pyqt.sourceforge.net/Docs/PyQt4/qprocess.html#finished
void finished (int, ::QProcess::ExitStatus)
This is the default overload of this signal.
This signal is emitted when the process finishes. exitCode is the exit
code of the process, and exitStatus is the exit status. After the
process has finished, the buffers in QProcess are still intact. You
can still read any data that the process may have written before it
finished.
QProcess.ExitStatus
This enum describes the different exit statuses of QProcess.
Constant..................Value.........Description
QProcess.NormalExit....... 0.......The process exited normally.
QProcess.CrashExit........ 1.......The process crashed.
我尝试使用此语法,但它不起作用
self.process.finished(0,QProcess_ExitStatus=0).connect(self.status)
备注:
状态就像任何插槽(任何操作)的符号,而不是特定的东西
更新:
为了了解问题,我有多个进程(将其视为队列)我需要 python 来执行第一个进程,并且只有在前一个进程退出时才移动到下一个进程通常不会使用 kill() 或 terminate()
强制退出
提前致谢
您不必在连接中指向符号,而是在 pyqtSlot 的帮助下指向插槽中的符号。
from PyQt4 import QtCore
class Helper(QtCore.QObject):
def __init__(self, parent=None):
super(Helper, self).__init__(parent)
self.process = QtCore.QProcess(self)
self.process.start("ping -c 4 google.com")
self.process.finished.connect(self.status)
@QtCore.pyqtSlot(int, QtCore.QProcess.ExitStatus)
def status(self, exitCode, exitStatus):
print(exitCode, exitStatus)
QtCore.QCoreApplication.quit()
if __name__ == '__main__':
import sys
app = QtCore.QCoreApplication(sys.argv)
h = Helper()
sys.exit(app.exec_())
更新:
from PyQt4 import QtCore
class Helper(QtCore.QObject):
def __init__(self, parent=None):
super(Helper, self).__init__(parent)
self.process = QtCore.QProcess(self)
self.process.start("ping -c 4 google.com")
self.process.finished.connect(self.on_finished)
@QtCore.pyqtSlot(int, QtCore.QProcess.ExitStatus)
def on_finished(self, exitCode, exitStatus):
if exitStatus == QtCore.QProcess.NormalExit:
self.status()
def status(self):
print("status")
我在 qt 中使用 python,但我找不到在 Qprocess 正常退出时触发信号的方法,根据 Pyqt 文档 finished() 信号可以采用 2 个参数 exitCode 和 exitStatus
这是 Pyqt 文档中关于 finished() 信号的描述
http://pyqt.sourceforge.net/Docs/PyQt4/qprocess.html#finished
void finished (int, ::QProcess::ExitStatus)
This is the default overload of this signal.
This signal is emitted when the process finishes. exitCode is the exit code of the process, and exitStatus is the exit status. After the process has finished, the buffers in QProcess are still intact. You can still read any data that the process may have written before it finished.
QProcess.ExitStatus
This enum describes the different exit statuses of QProcess.
Constant..................Value.........Description
QProcess.NormalExit....... 0.......The process exited normally.
QProcess.CrashExit........ 1.......The process crashed.
我尝试使用此语法,但它不起作用
self.process.finished(0,QProcess_ExitStatus=0).connect(self.status)
备注:
状态就像任何插槽(任何操作)的符号,而不是特定的东西
更新:
为了了解问题,我有多个进程(将其视为队列)我需要 python 来执行第一个进程,并且只有在前一个进程退出时才移动到下一个进程通常不会使用 kill() 或 terminate()
强制退出提前致谢
您不必在连接中指向符号,而是在 pyqtSlot 的帮助下指向插槽中的符号。
from PyQt4 import QtCore
class Helper(QtCore.QObject):
def __init__(self, parent=None):
super(Helper, self).__init__(parent)
self.process = QtCore.QProcess(self)
self.process.start("ping -c 4 google.com")
self.process.finished.connect(self.status)
@QtCore.pyqtSlot(int, QtCore.QProcess.ExitStatus)
def status(self, exitCode, exitStatus):
print(exitCode, exitStatus)
QtCore.QCoreApplication.quit()
if __name__ == '__main__':
import sys
app = QtCore.QCoreApplication(sys.argv)
h = Helper()
sys.exit(app.exec_())
更新:
from PyQt4 import QtCore
class Helper(QtCore.QObject):
def __init__(self, parent=None):
super(Helper, self).__init__(parent)
self.process = QtCore.QProcess(self)
self.process.start("ping -c 4 google.com")
self.process.finished.connect(self.on_finished)
@QtCore.pyqtSlot(int, QtCore.QProcess.ExitStatus)
def on_finished(self, exitCode, exitStatus):
if exitStatus == QtCore.QProcess.NormalExit:
self.status()
def status(self):
print("status")