Results 1 to 4 of 4

Thread: How to read/write sets of orderded numbers in binary

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3
    Thanked 39 Times in 39 Posts

    Default Re: How to read/write sets of orderded numbers in binary

    The easiest would be to store the dimensions to expect first, for example, this matrix:

    1 1 1
    2 2 2
    3 3 3

    Would be stored as

    3 3 1 1 1 2 2 2 3 3 3

    Where the first two threes would indicate that we're dealing with a 3x3 matrix. Then the data follow. Using an index, starting at 0 for the first one, then increasing you can find your matrix coordinate like this:

    row = index/width; // Integer division, always rounds down
    col = index%width; // Modulus

    The final check would be to ensure that the index == width*height when you have reached the end of the file.

    Also, when storing binary data using Qt, make sure to set your QDataStream version using myDataStreamObject->setVersion( xxx ); to ensure compatibility between Qt versions.

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

    kaydknight (10th March 2007)

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.