I'm Working with PySide, and seeking a way to restart my Qt app. Does this depends on python, or it has to be controlled by Qt?
BY ROSTYSLAV'S SUGGESTION BELLOW :
class MyAppMainWindow(QMainWindow):
def __init__(self):
self.EXIT_CODE_REBOOT = -15123123
exit_code = self.EXIT_CODE_REBOOT
def slotReboot(self):
print "Performing application reboot.."
qApp.exit( self.EXIT_CODE_REBOOT )
def main():
currentExitCode = 0
app = QApplication(sys.argv)
ex = MyAppMainWindow()
while currentExitCode == ex.EXIT_CODE_REBOOT :
currentExitCode = app.exec_()
return currentExitCode
if __name__ == '__main__':
main()
Obviously I didn't fully understand. Pleas help.
There's a nice way presented by Qt Wiki on how to make your application restartable.
The approach is based on recreation of QApplication instance and not killing current process.
It can be easily adopted to PySide like the next snippet shows:
EXIT_CODE_REBOOT = -15123123 # you can use any unique value here
exit_code = EXIT_CODE_REBOOT # Just for making cycle run for the first time
while exit_code == EXIT_CODE_REBOOT:
exit_code = 0 # error code - no errors happened
app = QApplication(sys.argv)
...
exit_code = app.exec()
You just need to setup proper exit code through the API presenteed by QApplication before finishing your app. The you can hook up new configuration or whatever you need when new application instance is created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With