Results 1 to 5 of 5

Thread: Parsing/extracting from a binary QByteArray

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    10
    Thanked 31 Times in 25 Posts

    Default Re: Parsing/extracting from a binary QByteArray

    If the contents of the 30-byte chunks is fixed as you indicate, and if the endianess is the same, then Santosh's solution is the way to go.

    Otherwise you must encode it like you did, but you can write it more compact like :
    Qt Code:
    1. unsigned char *pData = (unsigned char*)chunk.data();
    2. quint32 long_data1 = pData[0] | ((quint32)pData[0+1]<<8) | ((quint32)pData[0+2]<<16) | ((quint32)pData[0+3]<<24);
    To copy to clipboard, switch view to plain text mode 
    And to make it more readable, create a #define to extract the data, subsituting the '0' for the parameter in your define. And create different #defines for different data types.

    As a sidenote... I don't think that parsing such small chunks of data in a separate thread will speed up things. Possibly the effort of task switching is greater than the effort of parsing.

    Best regards,
    Marc

  2. The following user says thank you to marcvanriet for this useful post:

    Phlucious (2nd December 2011)

Similar Threads

  1. Replies: 1
    Last Post: 22nd June 2011, 08:12
  2. Extracting int values from QByteArray
    By Tottish in forum Newbie
    Replies: 4
    Last Post: 7th April 2010, 10:41
  3. Replies: 1
    Last Post: 20th January 2010, 09:01
  4. Replies: 9
    Last Post: 25th July 2009, 13:27
  5. Extracting xml fragment from QXmlStreamReader
    By Gopala Krishna in forum Qt Programming
    Replies: 5
    Last Post: 1st December 2007, 09:14

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
  •  
Qt is a trademark of The Qt Company.