#include#include int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QProcess process; process.start("ls", QStringList() << "-l"); process.waitForStarted(); process.closeWriteChannel(); process.waitForFinished(); return app.exec(); }
#includeThis example launches the "echo" command as a child process with the argument "Hello, world!", closes its write channel, and waits for it to finish. The process then reads the output of the command and logs it. The QProcess class is part of the Qt Core package library.#include int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QProcess process; process.start("echo", QStringList() << "Hello, world!"); process.waitForStarted(); process.closeWriteChannel(); process.waitForFinished(); QString output = QString(process.readAll()).trimmed(); qDebug() << "Process output:" << output; return app.exec(); }