how to restart my own qt application?

2019-01-07 22:30发布

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

Can somebody please show me an example?

8条回答
等我变得足够好
2楼-- · 2019-01-07 22:45

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.

查看更多
\"骚年 ilove
3楼-- · 2019-01-07 23:00

To restart application, try:

#include <QApplication>
#include <QProcess>

...

// restart:
qApp->quit();
QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
查看更多
登录 后发表回答