QProcess::startDetached() not show console window

我与影子孤独终老i 提交于 2019-12-10 22:58:30

问题


I have a GUI program that start cli program by click button. I want to see console window and don't need wait until cli program end. So I use code like this:

QProcess::startDetached("cmd.exe");

After click button I don't see console window. But see cmd.exe process in task manager.

I tried use system() command but it freeze my app before cli program end.

Is there any way to make window visible?


回答1:


It is the expected behavior. At least in Windows startDetached is equivalent to calling CreateProcess with the DETACHED_PROCESS flag, where the new process does not inherit its parent's console. It makes sense that in other platforms the method would do something similar.

In this case you'd had to manually allocate a new one using AllocConsole on the new process (be aware that you may need to redirect the streaming handles to the new console), or try to start the process in a different way (check CreateProcess or fork).

BTW, the reason system freezes your application is because it is a synchronous call, so it won't return the control until the other process finishes. You may try calling system from a separate thread and it this way you avoid blocking the main event loop of your application.



来源:https://stackoverflow.com/questions/42258892/qprocessstartdetached-not-show-console-window

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