[Qt] QProcess::startDetached() 避免弹窗,或者窗口一闪而过
阅读原文时间:2023年07月09日阅读:2

主动宣告setProcessState(QProcess::NotRunning)

或者在堆上new一个QProcess。

出处:

 https://stackoverflow.com/questions/33874243/qprocessstartdetached-but-hide-console-window

I had exactly the same problem, and could not solve it in a clean way. I have found 2 options:

  1. Hacky way: Subclass QProcess and call setProcessState(QProcess::NotRunning); after starting the process. This will prevent the destructor to terminate the process. But it relies on an implementation detail of QProcess
  2. Create a memory leak: Dynamically create the QProcess on the heap, but never delete it, and thus never invoke its destructor

{
QProcess *process = new QProcess;
process->start("taskkill", QStringList() << "/f" << "/im" << "My Service.exe");
}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章