Kyle Dixon
Kyle Dixon

Reputation: 305

QProcess not invoking finished?

I tried implementing the suggestion from subprocess Popen blocking PyQt GUI but it appears that the onFinished function is never getting invoked.

class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):

[...]

    def Run_PnL_Script(self):
        self.Run_PnL.setEnabled(False)
        self.Run_PnL.setStyleSheet("background-color: #D3D3D3; color: #FFFFFF")
        self.PnL_Status.setText("Running...")
        process = QtCore.QProcess(self)
        process.finished.connect(self.onFinished)
        process.startDetached("cmd.exe", ["/c", "K:\Market Risk\Risk App\Batches\RTest.bat"])

    def onFinished(self, exitCode, exitStatus):
        self.PnL_Status.setText("Complete.")
        self.Run_PnL.setEnabled(True)
        self.Run_PnL.setStyleSheet("background-color: #4582EC; color: #FFFFFF")

[...]

Thanks in advance for the help.

Upvotes: 1

Views: 231

Answers (1)

eyllanesc
eyllanesc

Reputation: 244282

You have 2 errors:

  • When you finish executing a command in cmd.exe does not imply that you close the cmd.exe, so you must close it using the EXIT command at the end of the .bat.

RTest.bat

:: Another commands
EXIT
  • Do not use startDetached() since this is a static method that creates an internal QProcess different from the "process" variable, you must use the start() method.
# ...
process = QtCore.QProcess(self)
process.finished.connect(self.onFinished)
process.start("cmd.exe", ["/c", "K:\Market Risk\Risk App\Batches\RTest.bat"])

Upvotes: 1

Related Questions