hi everyone, i have the "if" statement below. the purpose of this 'if' statement is to check if the string 'LoginDetail@#%$^*&_FhDKooKSE' is contained in the QByteArray 'readAll', if the condition is true the 'else' part of the 'if' statement is executed otherwise whatever is in the QByteArray is displayed on screen. the else part works fine but the 'false' condition displays empty strings even though there is something to display in the QByteArray. I think this is because the statement 'socket.readAll()' is executed twice, first in the condition of the 'if' statement secondly just below the 'if' statement.
I think this is because the statement 'socket.readAll()' is executed twice, first in the condition of the 'if' statement secondly just below the 'if' statement.
You thought correct.
how can i fix this?
Simple.
Store the result of socket->readAll() to a QByteArray, then operate on that QByteArray.
1 2 3 4 5 6 7 8 9
void Client::readSocket()
{
QByteArray data = socket->readAll();
if(!data.contains("LoginDetail@#%$^*&_FhDKooKSE"))
qDebug() << data <<endl;
else
qDebug() << "Login window is opened";
}