All the answers above are incorrect due to the nature of the question. @aakashjain asks for a detached process. What you guys suggest works only in the case the started process is still attached.
QProcess p
p.startDetached(...)
is the same as
QProcess::startDetached(...)
QProcess::startDetached() is a static method and it is NOT part of any object or returns one. Once you call this method and it succeeds the process will no longer be attached in any way to the process that has spawned it (your application).
I suggest you look first at the official documentation on this method and then read more about interprocess communication as well how to pipe the output of one process to another (in this case detached process to the terminal).
I stumbled upon the issue even of basic controll using QProcess::startDetached() in PyQt4 where I did exaclty what the @DmitrySokolov suggested. For my surprise the state was always zero, nothing could be set or retrieved using the QProcess non-static method. After some digging and asking around it was pointed to me exactly what I've written at the beginning of my answer - if you use QProcess::startDetached(), the control that follows has to be through the system tools (such as the kill command, pipes etc.) because you have no object you can actually work with.
QProcess::startDetached() offers two important return values:
- the return value of the method itself - a boolean, which tells you if the starting of the process has succeeded (==true) or failed (==false)
- the qint64 * pid pointer argument of the function - if the process has been started successfully, the pid will contain the PID (Process Identifier) of the detached process
You can use this PID to interact with the process however you like (and the process itself allows you to of course ;)) - you can terminate it, pipe its output, put it to sleep etc.
Now back to your problem. There are three solutions here:
- Start a child process - the process will be contained in a QProcess object, which you can interact with as @DmitrySokolov has described. However this will block you main thread, which handles the UI until the child process has finished its task and has stopped (main thread runs inside the process of your Qt app). I doubt you want your UI to freeze (as you have noticed by experimenting on your own) especially since we are talking about downloading possibly large contents of video data...
- Start a detached process - what I've described before this list of solutions. It requires however a more in debt understanding of interprocess communication. If you are up for it and want to spend some time working on this topic (I can only encourage you to do that!), do it
- Start a thread and a child process in it - not only you will have a really neat control over the download task but you will also be able to give great feedback via slots and signals to the UI, which will improve the user experience a lot. This is the most widely used way for such task and I can also see in your comment that you want to output the progress in
ui->descBox
(you can also add a QProgressbar to make the output more user-friendly and do the stdout/stderr thing in the background just for you to see). I haven't tested this to be honest but it should work.