Starting QProcess from QThread [duplicate]

心已入冬 提交于 2019-12-13 05:51:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!