主动宣告 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

    SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
{
    QProcess *process = new QProcess;
    process->start("taskkill", QStringList() << "/f" << "/im" << "My Service.exe");
}

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄