问题
I was using QThreads in Qt where my need is to launch a command-line executable from within a Qt thread and run the same within the thread's context.
I have used the below mentioned code for the same which seems to be running fine. However, I wanted to know if this kind of usage is permitted since we are launching a QProcess from within a QThread.
void Help_Menu_Thread::run()
{
Insert_Log("INFO::Help file referred by Admin");
QProcess HelpStart;
HelpStart.execute("c:\\windows\\hh.exe LPRS_help.chm");
HelpStart.close();
}
Awaiting your response.
Regards,
Saurabh G.
回答1:
It is safe to use this way as long has your main program doesn't have to wait for output of qprocess or for its completion. This helpstart process will start with the thread being it parent process running independently.But it would be more safe if you use HelpStart.waitForFinished()
before you call HelpStart.close();
来源:https://stackoverflow.com/questions/10891923/starting-qprocess-from-qthread