问题
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