Results 1 to 3 of 3

Thread: QProcess finishes imediately (it shouldn't)

  1. #1
    Join Date
    Nov 2011
    Posts
    51
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QProcess finishes imediately (it shouldn't)

    I'm running Windows XP and I'm using Qt Creator, and here is the code I use to create the process and to log what is happening:

    Qt Code:
    1. QProcess process;
    2. cout << "Starting process..." << endl;
    3. process.start("ping 1.1.1.1 -n 1 -w 3000 > nul");
    4. process.waitForStarted();
    5. cout << "Process started" << endl;
    6. process.waitForFinished();
    7. cout << "Process finished" << endl;
    To copy to clipboard, switch view to plain text mode 

    The command line "ping 1.1.1.1 -n 1 -w 3000 > nul" is supposed to make the program halt for 3 seconds (3000 milliseconds) between two pings before it times out, but the text "Process finished" is written to cout almost simultaneously as the other two lines of text, sometimes seemingly at the same time. If the command line is entered directly into the terminal (MS Command Prompt) instead, the command runs for three seconds before the terminal takes in keyboard input again, so it is not the command line that is wrong. So why isn't this working in Qt?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess finishes imediately (it shouldn't)

    QProcess is not running a shell thus things like ">" will not work. It doesn't make sense to use it here anyway since QProcess is capturing all the output of the slave process.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2011
    Posts
    51
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess finishes imediately (it shouldn't)

    Okay, that seems reasonable. I started another program instead which also waits for a centain amount of time, and that worked fine. Thanks!

Similar Threads

  1. QProcess finishes but never emits finished signal
    By BettaUseYoNikes in forum Qt Programming
    Replies: 2
    Last Post: 3rd December 2011, 08:01
  2. QThread wait for signal finishes
    By ArkKup in forum Newbie
    Replies: 1
    Last Post: 21st November 2011, 04:47
  3. Replies: 17
    Last Post: 29th March 2011, 22:52
  4. QNetworkReply::uploadProgress finishes immediately
    By peppermg in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2010, 17:19
  5. Replies: 2
    Last Post: 7th January 2010, 09:52

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.