Get the ping from a remote target with Qt (Windows/Linux)

前端 未结 4 2821
不知归路
不知归路 2021-02-20 17:19

Currently I use this code for retrieving the ping of a target system. However it works so far only under linux and it is likely dependent on the locale settings. To add suppor

4条回答
  •  萌比男神i
    2021-02-20 17:45

    You can ping on both Windows and Linux using this:

       QStringList parameters;
    #if defined(WIN32)
       parameters << "-n" << "1";
    #else
       parameters << "-c 1";
    #endif
    
       parameters << m_sHostName;
    
       int exitCode = QProcess::execute("ping", parameters);
       if (exitCode==0) {
           // it's alive
       } else {
           // it's dead
       }
    

提交回复
热议问题