[Qt] QProcess::startDetached() 避免彈窗,或者窗口一閃而過


主動宣告 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");
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM