Qt: kill current process?

Is there a way in Qt to terminate a'la of the TerminateProcess

current process?

QProcess :: kill () appears to only apply to other external processes.

+2


source to share


2 answers


Here's my code for win / mac / linux, although not portable to 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
}

      

+4


source


Just call TerminateProcess directly, or if you want some platform independent: exit ()



-1


source







All Articles