Results 1 to 2 of 2

Thread: Problem in reading data from server.

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Problem in reading data from server.

    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

    Qt Code:
    1. int *ptr_data;
    2. int array[8] = {63,33,30,31,30,31,32,31};
    3. ptr_data = &array[0];
    4. QByteArray block, block1;
    5. QByteArray arr((char *)ptr_data,4);
    6. QDataStream in(&block, QIODevice::ReadOnly);
    7. in.setVersion(QDataStream::Qt_4_5);
    8. qDebug()<<"Read data"<<socket->bytesAvailable();
    9. block=socket->readAll();
    10. qDebug()<<"block"<<block.toHex();
    11. block1=block.remove(0,24);
    12. qDebug()<<"Size"<<block.size();
    13. qDebug()<<"block 1 contents"<<block1;
    14. qDebug()<<"size of block1"<<block1.size();
    15. //block.contains(block1);
    16. qDebug()<<"compare"<<block.contains(block1);;
    17. for(int i=0; i<block1.size();i++)
    18. {
    19. block.contains(block1);
    20. if(block1[i]==arr[i])
    21. qDebug()<<"message";
    22. }
    To copy to clipboard, switch view to plain text mode 

    Please guide me what i am doing wrong.

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Problem in reading data from server.

    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.

Similar Threads

  1. Problem: Reading and editing text file data
    By dipeshtech in forum Newbie
    Replies: 2
    Last Post: 2nd May 2011, 23:47
  2. SQL Server data retrieving speed problem
    By Aleksandar in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2010, 13:52
  3. Problem with reading in data from a QTCPSocket
    By Denarius in forum Qt Programming
    Replies: 4
    Last Post: 24th April 2009, 08:54
  4. Replies: 7
    Last Post: 29th August 2008, 10:24
  5. problem with reading input data in qt
    By Ahmad in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2007, 10:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.