QProcess process; process.start("ls"); while (process.waitForReadyRead()) { if (process.canReadLine()) { QByteArray line = process.readLine(); qDebug() << line; } }
QProcess process; process.start("ping", QStringList() << "8.8.8.8"); process.waitForStarted(); while (process.state() == QProcess::Running) { if (process.canReadLine()) { QString line = QString::fromUtf8(process.readLine()); qDebug() << line; if (line.contains("Ping statistics")) { process.kill(); } } }This code starts a QProcess to execute the "ping" command with the argument "8.8.8.8" and waits for the process to start. It then enters a loop that reads lines from the standard output of the child process using the canReadLine() function. It prints each line to the console and checks if the line contains the text "Ping statistics". If it does, it kills the child process. Package library: Qt Core Module