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?
Forum Updated to NodeBB v4.3 + New Features

How to use QTProcess with ping command?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 2 Posters 6.4k 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 6 Jan 2016, 15:12 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 6 Jan 2016, 15:36 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
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 6 Jan 2016, 15:45 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 7 Jan 2016, 06:33
        1
        • S SGaist
          6 Jan 2016, 15:45

          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 7 Jan 2016, 06:33 last edited by
          #4

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

          1 Reply Last reply
          0
          • N Offline
            N Offline
            NTCYP
            wrote on 7 Jan 2016, 06:38 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

            1/5

            6 Jan 2016, 15:12

            • Login

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