Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to use QTProcess with ping command?
Qt 6.11 is out! See what's new in the release blog

How to use QTProcess with ping command?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 2 Posters 7.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NTCYP
    wrote on last edited by
    #1

    Hi,

    I am trying to use QT process as;

    // Create QProcess object
    proc = new QProcess();
    proc->start("ping", QStringList() << "-c 10" << QString(www.google.com));
    

    And I am gettig error as;

    ping: Invalid number '10'
    

    Any help please,

    Kind Regards

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NTCYP
      wrote on last edited by
      #2

      Ok. I found it.

      I shouldn't use "-c 10"... It was simply as;

      QString m_sHostName = "www.google.com";
      
      proc = new QProcess();
      proc->start("ping", QStringList() << QString(m_sHostName));
      

      Kind Regards,

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        The problem comes from how you prepare the argument list. You should use QStringList() << "-c" << "10" << "www.google.com"

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        N 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          The problem comes from how you prepare the argument list. You should use QStringList() << "-c" << "10" << "www.google.com"

          N Offline
          N Offline
          NTCYP
          wrote on last edited by
          #4

          @SGaist Thank you, it is working nicely... :)

          1 Reply Last reply
          0
          • N Offline
            N Offline
            NTCYP
            wrote on last edited by
            #5

            Here is a complete code. Hope helps someone...

            // WIFI PING TEST BUTTON 
            void DialogWIFI::on_PushButtonPing_clicked()
            {
                QString m_sHostName = "www.google.com";
            
                // Clear text
                ui->TextEditResult->clear();
            
                // Create string command and argument
                m_sHostName = ui->LineEditHostName->text();
            
                ui->TextEditResult->append(m_sHostName);
            
                // Create QProcess object
                proc = new QProcess();
                proc->start("ping", QStringList() << "-c" << "3" << QString(m_sHostName));
                QCoreApplication::processEvents();
            
                // Show output
                connect(proc, SIGNAL(readyReadStandardOutput()), this, SLOT(rightMessage()));
                connect(proc, SIGNAL(readyReadStandardError()), this, SLOT(wrongMessage()));
            }
            
            
            // Show right message
            void DialogWIFI::rightMessage()
            {
                QByteArray strdata = proc->readAllStandardOutput();
                strdata = strdata.simplified();
                strdata = strdata.trimmed();
            
                ui->TextEditResult->setTextColor(Qt::black);
                ui->TextEditResult->append(strdata);
                ui->TextEditResult->append("<br>");
            
            }
            
            
            // Show wrong message
            void DialogWIFI::wrongMessage()
            {
                QByteArray strdata = proc->readAllStandardError();
                ui->TextEditResult->setTextColor(Qt::red);
                ui->TextEditResult->append(strdata);
            }
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved