且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在QProcess中执行shell命令.

更新时间:2023-11-30 11:10:52

尝试以下示例:

QProcess sh;
sh.start( "sh", { "-c", "ifconfig | grep inet" } );

if ( !sh.waitForFinished( -1 ) )
{
    qDebug() << "Error:" << sh.readAllStandardError();
    return -1;
}

const auto output = sh.readAllStandardOutput();
// ...

waitForFinished()应该在阻止模式下调用,并且必须检查它是否成功.

waitForFinished() should be called in blocking mode and it must be checked if it was successful or not.