QProcess process; process.start("ls /invalid/path"); if (!process.waitForFinished()) { QString errorMsg = process.errorString(); qDebug() << "Error: " << errorMsg; }
QProcess process; process.start("echo hello world"); if (!process.waitForFinished()) { QString errorMsg = process.errorString(); qDebug() << "Error: " << errorMsg; } else { QString stdoutOutput = process.readAllStandardOutput(); qDebug() << "Output: " << stdoutOutput; }In this example, we start a process that prints "hello world" to the console. We then use the waitForFinished method to block until the process has completed. If there is an error, we retrieve the error message using errorString. If the process completes successfully, we retrieve the output using readAllStandardOutput method. Package library: The QProcess class is part of the Qt Core library.