PDA

View Full Version : Problem in reading data from server.



Niamita
12th August 2011, 06:53
Hi all
I am reading data from server, but it contains something with my data.
i have to do that i am reading data in a bytearray and i am comparing this array with my initializea array but it is not giving appropriate result.My code is


int *ptr_data;
int array[8] = {63,33,30,31,30,31,32,31};
ptr_data = &array[0];
QByteArray block, block1;
QByteArray arr((char *)ptr_data,4);
QDataStream in(&block, QIODevice::ReadOnly);
in.setVersion(QDataStream::Qt_4_5);
qDebug()<<"Read data"<<socket->bytesAvailable();
block=socket->readAll();
qDebug()<<"block"<<block.toHex();
block1=block.remove(0,24);
qDebug()<<"Size"<<block.size();
qDebug()<<"block 1 contents"<<block1;
qDebug()<<"size of block1"<<block1.size();
//block.contains(block1);
qDebug()<<"compare"<<block.contains(block1);;
for(int i=0; i<block1.size();i++)
{
block.contains(block1);
if(block1[i]==arr[i])
qDebug()<<"message";
}

Please guide me what i am doing wrong.

mvuori
12th August 2011, 23:30
Sorry to say, but your code is such a mess that not many people will even try to understand it, and most that do try, will not succeed.
For example: checks that do nothing: block.contains(block1);
There are byte arrays and integrer arrays -- which again are sure to make any file operation fail.
And comments that just confuse but don't explain: //block.contains(block1);
And nobody knows what the file lyou read really ooks like.
There are removals from the byte arrays and funny array assignments that I believe not many understand rightaway and nobody _should_ need to study without explanation (without being paid to).
I deem this code hopeless.
My advice: write it again. Writing comments in the code will help _you_ understand what you are doing.