Solved Regarding QProcess:: Not able to read data from the console
-
What is your current code?
Also, if you have access to the source of the voice recognition software you can send data directly in raw format (using
toBase64()
) and receive it more easily -
@VRonin said in Regarding QProcess:: Not able to read data from the console:
Also, if you have access to the source of the voice recognition software you can send data directly in raw format (using toBase64()) and receive it more easily
First i tried using directly and was able to send the output through the signal...but voice recognition has some callback functions which does not return control back to the function from where it is called so...i made this voice recog as a separate process.
-
@VRonin said in Regarding QProcess:: Not able to read data from the console:
What is your current code?
#include "ProcessWidget.h" ProcessWidget::ProcessWidget(QWidget *parent) : QWidget(parent) { m_btn= new QPushButton("click here",this); connect(m_btn,SIGNAL(clicked()),this,SLOT(vStartProcess())); } void ProcessWidget::vStartProcess() { qDebug()<<"entered the function"<<endl; const QString program = QStringLiteral("/home/ubuntu/Documents/Sample_Examples_Qt_Qml/VoiceRecognition/VoiceRecognition"); QProcess* myProcess = new QProcess; // connect(myProcess,&QProcess::readyReadStandardOutput,[myProcess]()->void{ // qDebug()<<"Output: "<< myProcess->readAllStandardOutput()<<endl; // }); connect(myProcess,&QProcess::readyReadStandardError,[myProcess]()->void{ qDebug()<<"Output: "<< myProcess->readAllStandardError(); const QString processOut = QString::fromLatin1(myProcess->readAllStandardError()); const QRegularExpression regXp("Received Command"); const auto regXpMatch = regXp.match(processOut); if(regXpMatch.hasMatch()){ qDebug() << "Output of regular exp is: "<< regXpMatch.captured(1); } }); connect(myProcess,SIGNAL(finished(int)),myProcess,SLOT(deleteLater())); myProcess->start(program); qDebug()<<"process started waiting for output"<<endl; connect(this,&ProcessWidget::destroyed,myProcess,&QProcess::kill); }
-
I guess you are not really familiar with the perl regular expression syntax.
const QRegularExpression regXp("Received Command");
should beconst QRegularExpression regXp("Received Command:\\s*(.+)");
-
@VRonin thanks for the reply...i got the output as expected.
but the output which i am getting is appending with (" ") and \ y is it like that ? and how to remove this double quotes and \ ? -
@Naveen_D The double-quotes are comming from qDebug(), they are not really in your string (you can try with std::cout to verify).
-
@jsulm yes sir i got that...thanks for the information