Calling command prompt from Qt application without freezing?
In my Qt GUI application, I am calling the command prompt through:
system("lots.exe & of.exe && 开发者_运维问答commands.exe");
It opens up the command prompt (like I want it to), but freezes the Qt GUI application until I close the command prompt. Is there someway to prevent this? I saw that there is a QProcess class, but can't get it to bring up the command prompt.
Any help would be greatly appreciated!
QProcess
is really the answer. If you want to use something like system()
you'll have to either put the call in another thread or use popen
or something simmilar for your platforms.
QProcess
does have the setReadChannel
which you could use to display your own console window to show the output.
You just need to put that system call in a separate thread.
If you do not need any of the output, the easiest way would be to use QProcess::startDetached().
http://doc.qt.io/archives/4.6/qprocess.html#startDetached
If you do need the output, QtConcurrent::run with a futurewatcher containing the output would be less overhead/work than deriving QThread.
精彩评论