Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using QProcess.finished() in Python 3 and PyQt

How can I use the QProcess.finished() to call a different Python3 script.

Here's the script I call:

#!/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()

To call the script I use the code as seen here

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()

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

like image 321
Otmarius Avatar asked Sep 25 '26 14:09

Otmarius


1 Answers

You can't get a signal when you use startDetached() because you have no object. Use ordinary start() instead.

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_())
like image 199
Alexander Lutsenko Avatar answered Sep 28 '26 05:09

Alexander Lutsenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!