Results 1 to 2 of 2

Thread: Fastest way to read structure from QTcpSocket

  1. #1
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Question Fastest way to read structure from QTcpSocket

    Hello All,

    I have got one problem which is resolved in http://www.qtcentre.org/threads/57634-SOLVED-Unable-to-read-data-by-QDataStream .
    But i want to know that, is there any other fastest way to read all the data from socket in a structure.

    My current structure is
    Qt Code:
    1. typedef struct hShakeAckPkt
    2. {
    3. unsigned short Id; // 0XFEFE
    4. unsigned short BlockSize; // 45
    5. int Reserved1[2]; // fill with 0
    6. unsigned short FeedType; // fill with 0
    7. unsigned short Reserved2[3]; // fill with 0
    8. unsigned short Major; // 1
    9. unsigned short Minor; // 4
    10. unsigned char ProgramId[21]; // "CTCL" rest with '\0'
    11.  
    12. }hShakeAckPkt;
    13.  
    14. QDataStream & operator << (QDataStream &out, const hShakeAckPkt &hand_shake_pkt);
    15. QDataStream & operator >> (QDataStream &in, hShakeAckPkt &hand_shake_pkt);
    To copy to clipboard, switch view to plain text mode 

    And the code for reading the data from the socket is
    Qt Code:
    1. QDataStream &operator <<(QDataStream &out, const hShakeAckPkt &hand_shake_pkt)
    2. {
    3. out << hand_shake_pkt.Id;
    4. out << hand_shake_pkt.BlockSize;
    5.  
    6. for(int i = 0; i < 2; ++i)
    7. out << hand_shake_pkt.Reserved1[i];
    8.  
    9. out << hand_shake_pkt.FeedType;
    10.  
    11. for(int i = 0; i < 3; ++i)
    12. out << hand_shake_pkt.Reserved2[i];
    13.  
    14. out << hand_shake_pkt.Major;
    15. out << hand_shake_pkt.Minor;
    16.  
    17. for(int i = 0; i < 21; ++i)
    18. out << hand_shake_pkt.ProgramId[i];
    19.  
    20. return out;
    21. }
    22.  
    23. QDataStream &operator >>(QDataStream &in, hShakeAckPkt &hand_shake_pkt)
    24. {
    25. in >> hand_shake_pkt.Id;
    26. in >> hand_shake_pkt.BlockSize;
    27.  
    28. for(int i = 0; i < 2; ++i)
    29. in >> hand_shake_pkt.Reserved1[i];
    30.  
    31. in >> hand_shake_pkt.FeedType;
    32.  
    33. for(int i = 0; i < 3; ++i)
    34. in >> hand_shake_pkt.Reserved2[i];
    35.  
    36. in >> hand_shake_pkt.Major;
    37. in >> hand_shake_pkt.Minor;
    38.  
    39. for(int i = 0; i < 21; ++i)
    40. in >> hand_shake_pkt.ProgramId[i];
    41.  
    42. return in;
    43. }
    To copy to clipboard, switch view to plain text mode 

    Now i want to know that, is there any other fastest way to read all the data in structure memory. (With or without QDataStream)

    ?????
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

  2. #2
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Fastest way to read structure from QTcpSocket

    I'll certainly happy to see that too But I'm worried that with QDataStream there is no other way to do serialization/deserialization without going after each item of the struct. Now about without the QDataStream, maybe this article will do the trick (depending in which direction you want to do it: http://smartqt.blogspot.com/2014/05/...-and-from.html).
    May the Lord be with you. Always.

Similar Threads

  1. Replies: 5
    Last Post: 3rd December 2013, 23:41
  2. fastest way to read large files (with mixed content)
    By timmu in forum Qt Programming
    Replies: 8
    Last Post: 10th September 2012, 11:09
  3. Qvector warnings 'read only structure'.
    By tonnot in forum Newbie
    Replies: 4
    Last Post: 13th July 2011, 11:27
  4. QtcpSocket read behavior
    By grisson in forum Qt Programming
    Replies: 5
    Last Post: 14th August 2010, 17:31
  5. Read Text file using structure..
    By umulingu in forum Qt Programming
    Replies: 7
    Last Post: 14th September 2009, 12:22

Tags for this Thread

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.