Qt:杀死当前进程? [英] Qt: kill current process?
本文介绍了Qt:杀死当前进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Qt中是否有一种方法可以终止当前进程'la TerminateProcess
?
Is there a way in Qt to terminate a'la TerminateProcess
the current process?
QProcess :: kill()似乎仅适用于其他外部程序.
QProcess::kill() seem to be only applicable to other, external processes.
推荐答案
这是我的win/mac/linux代码,尽管不能移植到其他操作系统上.
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
}
这篇关于Qt:杀死当前进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文