Qt: kill current process?

走远了吗. 提交于 2019-12-11 03:49:45

问题


Is there a way in Qt to terminate a'la TerminateProcess the current process?

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


回答1:


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
}



回答2:


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



来源:https://stackoverflow.com/questions/1533200/qt-kill-current-process

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!