Pergunta

I am connecting my code to an existing server and i am able to get response from the server.

But the problem is the content of the response is too large to be handled in a simple way.

Right now below is the piece of code that i use it to retrieve data.

socket->waitForReadyRead(1000);
    array = socket->readAll();
    for(int i=0; i< array.size();i++){
        //qDebug()<< array[i];
        test += array[i];
    }

    qDebug()<< "cmd Part 2: ";
    socket->waitForReadyRead(1000);
    array = socket->readAll();
    for(int i=0; i< array.size();i++){
        //qDebug()<< array[i];
        test += array[i];
    }

I have problems with simplifying the above code with for loop.

I do not know how to implement the socket->waitForReadyRead inside my for loop. Can anyone please help me on this?

Foi útil?

Solução

A basic solution would be:

while (socket->waitForReadyRead(1000))
{
    QByteArray array = socket->readAll();
    // do stuff
}

The loop will exit when the read times out or there is an error (e.g. the socket is closed).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top