Results 1 to 3 of 3

Thread: Size Of QBuffer Not Correct?

  1. #1
    Join Date
    Jun 2010
    Posts
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Size Of QBuffer Not Correct?

    I have a small problem with QBuffer. I'm writing PNGs to it and writing the byte array in my map file using fwrite in this format:

    Size
    Data

    When I read the first image from the map file is says its size is 304, but that is not correct because when I try to read the second image the size reads as zero and the image is never read correctly.

    Is 304 not the size of the array in bytes? If so then the image is not being written correctly in first place.
    Last edited by justin123; 19th April 2011 at 22:38.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Size Of QBuffer Not Correct?

    Post the code you are using

  3. #3
    Join Date
    Jun 2010
    Posts
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Size Of QBuffer Not Correct?

    Qt Code:
    1. void Tileset::write( FILE *file)
    2. {
    3. for (int i = 0; i < mTiles.size(); ++i)
    4. {
    5. QBuffer buffer( &ba);
    6. unsigned int size = 0;
    7.  
    8. buffer.open( QIODevice::WriteOnly);
    9. mTiles[i]->image().save( &buffer, "PNG", -1);
    10. buffer.close();
    11.  
    12. size = (unsigned int)ba.size();
    13. char *data = new char[size];
    14. data = ba.data();
    15.  
    16. fwrite( &size, sizeof(unsigned int), 1, file);
    17. fwrite( data, sizeof(char), size, file);
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. jpeg quality ignored when saving to a QBuffer
    By hakiim35 in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2010, 11:05
  2. QBuffer::readLine()
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2010, 20:57
  3. how can convert QFile to QBuffer?
    By learning_qt in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2009, 13:34
  4. QBuffer bytesWritten() problem
    By QAlex in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 09:05
  5. Replies: 12
    Last Post: 30th May 2009, 14:29

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.