PDA

View Full Version : QProcess start hangs application



hakermania
9th September 2011, 21:56
I am using QProcess to start an application with arguments defined in an QStringList.
Well, the program does quite some time to execute and during this time the program hangs.
I thought that Qt's functions was designed in such a way so as not to hang... (that's why I chose QProcess instead of system() anyway)
So, what I do is:


QString exec = "wget"; // <- making a variable, we will use 'exec' again, to download the image!
QStringList params1;
params1 << "-O" << "url" << "http://remote.location.com/remote_file";
check_url->start(exec, params1);
if(!check_url->waitForFinished()){
cerr << "Couldn't get file, possibly too slow internet connection (file size is 10 Kbytes)!\n";
delete check_url;
return false;
}
if(check_url->exitCode()){
cerr << "Something went wrong while downloading the file!\n";
delete check_url;
return false;
}
delete check_url;

And during this function the program hangs completely, is there any way qprocess not to append to the process it's attempting to run?

ChrisW67
9th September 2011, 22:57
If you want your application to be responsive while the wget runs then don't call the blocking function QProcess::waitForFinished():


Warning: Calling this function from the main (GUI) thread might cause your user interface to freeze.

The system() (http://linux.die.net/man/3/system) call would block just the same.

You can download a file from the network entirely inside your Qt code, so why use an external process at all?

hakermania
10th September 2011, 07:53
Hello ChrisW67, I now that it is possible but I already use the QProcess library for another task and if possible I would like to avoid adding another library...

If there's no solution I will maybe call qtconcurrentrun or download manually...

Lykurg
10th September 2011, 08:43
Or simply use QNetworkManager. Better add QtNetwork.dll to your app than fiddling with QProcess in a thread for downloading a simple file.