I am going to obtain the output of the following Linux command, to get all IP address for connected host in QT.
arp -n | grep 'C'
To achieve this, I wrote the following code:
QProcess proc;
proc.start("arp", QStringList() << "-n" << "|grep 'C'");
proc.waitForFinished();
QString output = proc.readAllStandardOutput();
qDebug()<<output;
int pos = 0;
QStringList ipList;
QRegExp re("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})");
while ((pos = output.indexOf(re, pos)) != -1)
{
ipList.append(re.cap(1));
pos += re.matchedLength();
}
qDebug()<<ipList;
But the output is empty when I add grep
option! If I remove grep
option the output is not empty.
proc.start("arp", QStringList() << "-n");