how to restart my own qt application?

后端 未结 8 1687
再見小時候
再見小時候 2020-11-30 09:39

i just asking myself how to restart my own qt application?

Can somebody please show me an example?

相关标签:
8条回答
  • 2020-11-30 10:25

    Doing a real process restart without subclassing:

    QCoreApplication a(argc, argv);
    int returncode = a.exec();
    if (returncode == -1)
    {
      QProcess* proc = new QProcess();
      proc->start(QCoreApplication::applicationFilePath());
    }
    return returncode;
    

    Edit for Mac OS like earlier example.

    To restart call

    QCoreApplication::exit(-1);
    

    somewhere in your code.

    0 讨论(0)
  • 2020-11-30 10:28

    This slight variation on Rubenvb's idea works with PyQt. clearSettings is the method that triggers the restart.

    class GuiMain
    
        #Most of implementation missing
    
        def clearSettings(self):
            #Clearing the settings missing
            QApplication.exit(GuiMain.restart_code)
    
        restart_code = 1000
    
        @staticmethod
        def application_main():
            """
            The application's main function. 
            Create application and main window and run them.
            """
            while True:
                app = QApplication(sys.argv)
                window = GuiMain()
                window.show()
                ret = app.exec_()
                if ret != GuiMain.restart_code:
                    break
                del window
                del app
    
    0 讨论(0)
提交回复
热议问题