Qt | Realization of software restart after clicking the button

Qt | Realization of software restart after clicking the button


Use Qt's global variable qApp.

qApp provides closeAllWindows and quit methods.

Using closeAllWindows is called step by step until all open windows are closed.

If you use the quit function, the application will exit directly and the window will be destroyed directly. That is to say, if you implement the closeEvent function and save the configuration file in this function, then closeEvent will not be called.

void MainWindow::on_pushButton_clicked()
{
    
    
    // 关闭所有窗口
    qApp->closeAllWindows();

    // 重新启动
    QProcess::startDetached(QApplication::applicationFilePath(), QApplication::arguments(), QDir::currentPath());
}

ends…

Guess you like

Origin blog.csdn.net/qq153471503/article/details/128042618