Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem while reading data and spliting that data from Qprocess
Forum Updated to NodeBB v4.3 + New Features

Problem while reading data and spliting that data from Qprocess

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Swinetha
    wrote on last edited by
    #1

    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.....

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Swinetha
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Because the signal is fired regularly when data have arrived. QProcess doesn't know when the process will end sending something to the stdout

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Swinetha
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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...

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved