read QProcess output to string

后端 未结 4 691
梦谈多话
梦谈多话 2020-12-09 04:03

I have a code that uses QProcess like this.

int main(int argc, char *argv[])
{
    int status=0;
    QProcess pingProcess;
    QString ba;
    QString exec =         


        
4条回答
  •  天命终不由人
    2020-12-09 04:40

    You shouldn't use QProcess::execute method, it's static and doesn't alter your pingProcess variable. You have no access to a process started using this method. You need to use start() method instead. Note that this method is asynchronous. You need to use waitForFinished and then read the data.

    pingProcess.start(exec, params);
    pingProcess.waitForFinished();
    QByteArray output = pingProcess.readAllStandardOutput();
    

提交回复
热议问题