Results 1 to 4 of 4

Thread: QProcess start hangs application

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QProcess start hangs application

    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:
    Qt Code:
    1. QString exec = "wget"; // <- making a variable, we will use 'exec' again, to download the image!
    2. QStringList params1;
    3. params1 << "-O" << "url" << "http://remote.location.com/remote_file";
    4. check_url->start(exec, params1);
    5. if(!check_url->waitForFinished()){
    6. cerr << "Couldn't get file, possibly too slow internet connection (file size is 10 Kbytes)!\n";
    7. delete check_url;
    8. return false;
    9. }
    10. if(check_url->exitCode()){
    11. cerr << "Something went wrong while downloading the file!\n";
    12. delete check_url;
    13. return false;
    14. }
    15. delete check_url;
    To copy to clipboard, switch view to plain text mode 
    And during this function the program hangs completely, is there any way qprocess not to append to the process it's attempting to run?
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QProcess start hangs application

    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() 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?

  3. The following user says thank you to ChrisW67 for this useful post:

    hakermania (10th September 2011)

  4. #3
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess start hangs application

    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...
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QProcess start hangs application

    Or simply use QNetworkManager. Better add QtNetwork.dll to your app than fiddling with QProcess in a thread for downloading a simple file.

  6. The following user says thank you to Lykurg for this useful post:

    hakermania (10th September 2011)

Similar Threads

  1. QProcess::start() failed when application runs from sudo
    By alenyashka in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2010, 07:35
  2. Replies: 5
    Last Post: 4th February 2010, 00:50
  3. QProcess problem (Main program hangs)
    By sincnarf in forum Qt Programming
    Replies: 5
    Last Post: 11th October 2007, 10:26
  4. QProcess hangs
    By Skizmo in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2007, 11:27
  5. QProcess start automaticaly needed application
    By raphaelf in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 15:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.