Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Get large amounts of data from the command line.



  • Hi!
    How do I get large amounts of data from the command line?
    If I do this , I only get the last part of the data:

    ParserApi::ParserApi()
    {
        process = new QProcess(this);
        connect(process, &QProcess::readyReadStandardOutput, this, &ParserApi::reply);
       process->start(" php gopack.php check_fines " + numberCar + " 0");
    }
    
    void ParserApi::reply()
    {
        QByteArray replyArray = process->readAllStandardOutput();    
        
            QJsonDocument doc = QJsonDocument::fromJson(replyArray);
        
            QJsonObject object1 = doc.object();    
        
            qDebug()<< doc;

  • Qt Champions 2019

    Since readyReadStandardOutput is called more than once you first have to collect the data in your internal buffer.


  • Lifetime Qt Champion

    Hi
    you have your buffer as a local variable so for each "read" you only keeping the last data.
    Move QByteArray replyArray;
    to the class so its a member (ask if you dont know what that means)
    and do

    void ParserApi::reply()
    {
    replyArray += process->readAllStandardOutput(); // add data to the member buffer

    and in ParserApi()
    {
    replyArray.clear(); // so you alreays start with clean buffer


Log in to reply