Results 1 to 4 of 4

Thread: [SOLVED] QByteArray append data in loop "wrong" end size

  1. #1
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default [SOLVED] QByteArray append data in loop "wrong" end size

    Hello,
    I have problem with appending dato into QByteArray from another QByteArray.
    What I want to do is do decompress file, zlib, but in my Decompress() function I can only decompress as much as bufferSize (int) data, so I need to divide my compressed size into smaller chunks, not greater then bufferSize.
    I do this as fallows, and I know that probably I should use QDataStram, but for the simplicity sake I use QByteArray.

    Qt Code:
    1. while( !ba.isEmpty() ){
    2.  
    3. QByteArray tmp = ba.left( 262144 );
    4.  
    5. if( ba.size() <= 262144 ){
    6. ba.remove( 0, ba.size() );
    7. }else{
    8. ba.remove( 0, 262144 );
    9. }
    10.  
    11. baUncompre.append( Decompress( tmp ) );
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 
    Then I write baUncompre to hdd.
    The problem is that baUncompre have wrong size. I know that Decompress() works fine.
    I tried baUncompre .resize( (int)uncompressedSize ); but that resize QBA not to the unompressed size but uncompressedSize +some more.

    Can someone shed some light where is error in my thinking.

    Best regards.

    EDIT: I checked and loop is fine, error is that append appends more then decompressed size or lees (depends if I resize baUncompre or not).

    EDIT: Sorry for garbage post, error was in Decompress() function.
    Last edited by Talei; 29th April 2010 at 16:36. Reason: updated contents

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: [SOLVED] QByteArray append data in loop "wrong" end size

    Hi Talei,
    You've obviously solved your previous problem with qUncompress from this thread. I am interested in this. I read the zlib and gzip docs and tried modifying code out of zpipe.c to inflate a gzip stream but nothing that I tried worked.

    Mind explaining what you've done or attaching some code?

    Thanks,
    Norm

  3. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [SOLVED] QByteArray append data in loop "wrong" end size

    If I correctly understand you question, You want to decode gzip stream, so code posted in thread that You linked (my last post, last code snippet ) do the trick.

    Personally, as stated at that thread http://www.qtcentre.org/threads/30031, I don't really know why qUncompress don't do the job. From inflate.c in qt It should decompress gzip.
    Try to use debug on qUncompress and trace zlib stream to see where the error is (I tried doing so, but failed to pinpoint where the error is ).

    AFAIK the "problem" is in inflateInit() and inflateInit2(). First one is used to initialize zlib stream, secound one can handle also gzip/zip. In my last snippet code in thread that was posted I used inflateInit2 and it works ( also fix while loop because it's incorrect). Or mess around with windowBits size, I use -8 and, if I remember correctly, one of this value didn't work (-15 or -8) for my gzip stream. If I understand correctly (I can be wrong on this one), windowBits is actually a header size for gzip/zip stream, and that amount of bytes are ignored by inflate, so depending on the original compressed stream that can vary.

    Look here for more inormation: http://www.zlib.net/manual.html for
    Qt Code:
    1. ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, int windowBits));
    To copy to clipboard, switch view to plain text mode 

    Best luck

    EDIT: I saw also, browsing qt src, that they use zlib for one of the *network classes (can't remember name thought) and not qUncomrpess, so probably it can't handle gzip after all (I dunno why).
    Last edited by Talei; 29th April 2010 at 18:39. Reason: updated contents

  4. The following user says thank you to Talei for this useful post:

    norobro (29th April 2010)

  5. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: [SOLVED] QByteArray append data in loop "wrong" end size

    I missed that. I guess I wasn't following the thread as closely as I thought.

    Your code works great. Turns out the problem with my code was that I was setting windowBits to a positive integer (15). When -8 is passed to inflateinit2, which I picked up from your code, it works.

    Thanks,
    Norm

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2010, 21:46
  2. Replies: 3
    Last Post: 25th August 2009, 13:03
  3. Replies: 1
    Last Post: 10th April 2009, 18:07
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. How to add a new word to QTextEdit with "append"
    By yagabey in forum Qt Programming
    Replies: 8
    Last Post: 6th January 2008, 11:50

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.