Problem while reading data and spliting that data from Qprocess
-
hai,
I am tried to read data from Qprocess continuously. Its working for just reading the data and displaying in textEdit.
working code is
@
void Hmi1::on_start_AV_clicked()
{
QString program;
QStringList arguments;
program = "/home/IFSS/programs//test";--
arguments<<"0x12"<<"0x34"<<"0x56"<<"0x78"<<"0x90"<<"0xab"<<"0xBC";
process =new QProcess();
process->setReadChannel(QProcess::StandardOutput);
process->start(program,arguments);
connect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(read_AV()));
}
@@
void Hmi1::read_AV()
{
QByteArray b1;
b1= process->readAllStandardOutput();
ui4->textEdit->setText(b1.data());
QMessageBox *MsgBxReadAV= new QMessageBox();
MsgBxReadAV->setText(QString::number(b1.length()));
MsgBxReadAV->show();
}
@from above code while clicking the pushbutton it willl start the qprocess and connect to a slot when readyReadStandardOutput() signal arised and it is displayed it textedit.
and the length of b1 is depends upon reading data.
now my problem is when I add the logic to split the data stored in b1 the length of the b1 is only 4096(4kb) only
logic is
@
void Hmi1::read_AV()
{
QByteArray b1;
QStringList strLines;
b1= process->readAllStandardOutput();
ui4->textEdit->setText(b1.data());
QMessageBox *MsgBxReadAV= new QMessageBox();
MsgBxReadAV->setText(QString::number(b1.length()));
MsgBxReadAV->show();
strLines = QString(b1).split("\n");
QString line_array[10000];
int i=0,j=0;
foreach (line_array[i++], strLines)
{
//line_array[i++]=line;
}
qDebug()<<"i="<<QString::number(i);
b1.clear();
process->closeReadChannel(QProcess::StandardOutput);
process->close();
}
@Is there any mistake in my program? let me know the where is the problem and what is the problem.....
-
Hi,
One thing that's wrong is that you connect your process after starting it, you might be loosing data.
Also, are you sure that the process has sent everything before stopping it ?
Does your application end after processing ?
Hope theses question helps
-
No i am not loosing any data I am getting total data and process was sending alla data before it was closing.
I found that while the data reading prom QProcess, the signal readyReadStandardOutput() was arised multiple times.
It is rised when it is calling 1st time, that QProcess::readAllStandardOutput() was read 4k bytes, again the signal was raised and it was read 64k bytes then it was continuously done for every 64k bytes data. I solved my problem but my quiestion is why it is raising multiple times?
-
Because the signal is fired regularly when data have arrived. QProcess doesn't know when the process will end sending something to the stdout
-
you said
bq. Because the signal is fired regularly when data have arrived.
but the data arriving only when we starting the process only and it is continuously reading the data. but why it was raised every time?
-
You don't read it continuously, you just read it once, do your processing then close the channels and the process.
The basic function is: data is received, readyRead is fired, you retrieve the data, new data arrives thus readyRead is fired again etc...