Hi,
i am using Qprocess to execute ping to check for a host to be online or not...
The problem is that the exit code that i recieve from the Qprocess->finished signal is always 2 no matter if i ping a reachable host or an unreachable one..
I am continuously pinging in a QTimer to a host(whose one folder i have mounted at client where the Qt app is running)...
when i catch the exit code as returned by ping in a slot connected to QProcess->finished signal.. i always recieve exit code as 2..
i cant use direct system call through system(ping) as it hangs my app for the time ping is active... i want it to be asynchronous so i switched to QProcess...
the following is the code snippet:
//Pinging function called inside a timer with timout 1000
QString exec="ping";
QStringList params;
if(!dBool)
{
//params << "-c1 1.1.1.11 -i1 -w1;echo $?";
params <<" 1.1.1.11 -i 1 -w 1 -c 1";//wont ping
cout<<"\n\npinging 11 ie wont ping";
}
else
{
//params << "-c1 1.1.1.1 -i1 -w1;echo $?";
params <<" 1.1.1.1 -i 1 -w 1 -c 1";//will ping
cout<<"\n\npinging 1 ie will ping";
}
ping->start(exec,params);
// the slot that connects with QProcess->finished signal
void QgisApp::pingFinished( int exitCode, QProcess::ExitStatus exitStatus )
{
cout<<"\n\nexitCode,exitStatus=="<<exitCode<<","<<exitStatus;//always 2,0!!
if(exitCode==0)
//if(dBool)
{
connectivity=true;
cout<<"\n\nONLINE";
}
else
{
connectivity=false;
cout<<"\n\nOFFLINE";
}
}
the
cout<<"\n\nexitCode,exitStatus=="<<exitCode<<","<<exitStatus
line always gives 2,0 as output no matter if 1.1.1.1 is pinged or 1.1.1.11 is pinged on terminal 1.1.1.1 is pingable and 1.1.1.11 is not (i switch bw ips through dBool flag that is set on keypress event to simulate online/offline host so that my app can behave accordingly)
Any inputs would be a great help..
Thanks.