Qt | 点击按钮后软件重启的实现

Qt | 点击按钮后软件重启的实现


利用Qt的全局变量qApp。

qApp提供了closeAllWindows和quit方法。

使用closeAllWindows是一级一级调用直到所有打开的窗口都被关闭。

而如果使用quit函数,则应用程序直接退出,窗口直接销毁,也就是说倘若你实现了closeEvent函数并在此函数内实现了配置文件的保存,那么closeEvent是不会被调用到的。

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

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

ends…

猜你喜欢

转载自blog.csdn.net/qq153471503/article/details/128042618