read QProcess output to string

后端 未结 4 705
梦谈多话
梦谈多话 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:23

    Did you try QByteArray QProcess::readAllStandardOutput() docs - here

    QString can be instantiated from QByteArray:

    QString output(pingProcess.readAllStandardOutput());
    

    As others mentioned, and I join to them, you should not use execute method and replace it with:

    pingProcess.start(exec, params);
    pingProcess.waitForFinished(); // sets current thread to sleep and waits for pingProcess end
    QString output(pingProcess.readAllStandardOutput());
    

提交回复
热议问题