I am having an issue while pinging to Destination / local IP using QProcess. QProcess returns “0” when ping is Successfull while Also when ping gives “Network is Unreachable” error (seen manually on terminal).
Actually I need to check the network connection in my application. To implement it, i used a very simple concept of ping using QProcess. I need to pop up a messagebox if there is any network error otherwise application starts normally without any popup message.
Here is my code for ping :
bool App::pingPcuStatus(void)
{
const QString IP ="192.168.49.44";
bool ret = false;
int status;
if ( IP == "0.0.0.0") {
status = 1;
}
else {
QProcess pingProcess;
QString exec = "ping";
QStringList params;
params << "-c" << "1" << IP;
status = pingProcess.execute(exec, params); //status = 0 , if Ping Successfull
pingProcess.close();
}
ret = (status) ? false : true;
return ret;
}
But while debugging I found, it returns “true” even i am not conected to network. (I tried manual ping with same command on terminal, it gives “Network is Unreachable” error).
This leads to a big bug in my case.
What is the best way to capture this error using QProcess or any other way to resolve it ???
Any Idea or Suggestion are welcome.
Original answer from https://stackoverflow.com/a/2148360/793796:
Then you can parse stdout & stderr.