开发者

Qt: kill current process?

开发者 https://www.devze.com 2022-12-08 02:58 出处:网络
Is there a way in Qt to terminate a\'la TerminateProcess the curre开发者_如何学Cnt process? QProcess::kill() seem to be only applicable to other, external processes.Here\'s my code for win/mac/linux,

Is there a way in Qt to terminate a'la TerminateProcess the curre开发者_如何学Cnt process?

QProcess::kill() seem to be only applicable to other, external processes.


Here's my code for win/mac/linux, though not portable for other OSes.

void killMe()
{
#ifdef Q_OS_WIN
  enum { ExitCode = 0 };
  ::TerminateProcess(::GetCurrentProcess(), ExitCode);
#else
  qint64 pid = QCoreApplication::applicationPid();
  QProcess::startDetached("kill -9 " + QString::number(pid));
#endif // Q_OS_WIN
}


Just call TerminateProcess directly, or if you want something platform independant: exit()

0

精彩评论

暂无评论...
验证码 换一张
取 消