Real time display of QProcess output in a textBrowser

ぐ巨炮叔叔 提交于 2019-12-01 21:18:31

to read standard output you need to either call waitForReadyRead() before reading stardard output , or you need to connect Qprocess's signal readyReadStandardOutput() to your slot and read standard output from slot.

also make sure that your QProcess is not on stack.

I tried following code works fine.

EDIT:

MyProcess::MyProcess(QObject *parent) :
    QObject(parent)
{
    QString program = "echo";
    QStringList arguments;
    arguments << "Hello";
    mProcess.start(program,arguments);
    connect(&mProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
    connect(&mProcess,SIGNAL(readyReadStandardError()),this,SLOT(readyReadStandardError()));
}

void MyProcess::readyReadStandardOutput(){
    qDebug()<< mProcess.readAllStandardOutput();
}

void MyProcess::readyReadStandardError(){
    qDebug() << mProcess.readAllStandardError();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!