Results 1 to 4 of 4

Thread: Ping and QProcess (exitcode() question)

  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 Ping and QProcess (exitcode() question)

    I have exactly this problem described here: http://stackoverflow.com/questions/1...achable-or-not but the solution provided didn't solve my problem. I am at a linux machine as the guy who had the similar problem. In fact the code is like this:

    Qt Code:
    1. QProcess *connected = new QProcess(0);
    2. QString exec="ping";
    3. QStringList params;
    4. params << "-c" << "1" << "http://www.google.com";
    5. connected->start(exec,params);
    6. if(!connected->waitForFinished())
    7. return false;
    8. cout << "The exit code is " << connected->exitCode() << endl;
    9. delete connected;
    To copy to clipboard, switch view to plain text mode 

    The ping process does execute and I always get the value '2' returned from connected->exitCode(). I have no idea why, but if I place instead of google.com the actual IP of google.com it seems to return the code correctly. But I don't know if google has static IP or not and I don't want to risk it anyway... Any suggestions or tips why is this happening and how to fix it ?
    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
    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: Ping and QProcess (exitcode() question)

    ping might be requiring a tty.
    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. The following user says thank you to wysota for this useful post:

    hakermania (30th August 2011)

  4. #3
    Join Date
    Aug 2011
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Ping and QProcess (exitcode() question)

    Try removing "http://" in line 4.

    params << "-c" << "1" << "www.google.com";

    Ping expects an IP or an hostname, "http://" isn't part of the hostname.

  5. The following user says thank you to thalis for this useful post:

    hakermania (30th August 2011)

  6. #4
    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: Ping and QProcess (exitcode() question)

    Quote Originally Posted by thalis View Post
    Try removing "http://" in line 4.

    params << "-c" << "1" << "www.google.com";

    Ping expects an IP or an hostname, "http://" isn't part of the hostname.
    good point
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

Similar Threads

  1. Question about QProcess::ExitCode() !
    By jackmack in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2010, 09:38
  2. Replies: 1
    Last Post: 13th November 2008, 10:46
  3. Any body who have a ping soure code using qt ?
    By longtrue in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2008, 11:29
  4. exitCode problem in QProcess
    By mattia in forum Newbie
    Replies: 7
    Last Post: 26th November 2007, 15:09
  5. How to ping a server ?
    By Nyphel in forum Newbie
    Replies: 2
    Last Post: 23rd April 2007, 11:27

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.