Results 1 to 15 of 15

Thread: Compress

  1. #1
    Join Date
    Oct 2007
    Location
    Bangalore
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Compress

    code for How to Compress a File In QT4???

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Compress

    Could you give more details? Do you want to use a specific algorithm?

  3. #3
    Join Date
    Oct 2007
    Location
    Bangalore
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compress

    Suppose if i pass any file for Example file.txt it should compress and give me in file.zip ...

    For that i need any code or Algorithm....

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Compress

    But do you want .zip specifically? Qt doesn't have zip support built in so you'd have to link with an additional library that performs zipping. But if you're interested in any kind of compression, Qt can do zlib (gzip) compression through qCompress().

  5. #5
    Join Date
    Oct 2007
    Location
    Bangalore
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compress

    I want to compress store in .zip format only .... I have used QCompress it is compressing but if i try to open that file.zip it's give me error ... and i can't be able to extract it...

  6. #6
    Join Date
    Oct 2007
    Location
    Bangalore
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compress

    I have used the following code


    QFile inFile("map.txt");
    inFile.Open(QIODevice::ReadOnly);
    QByteArray ba=inFile.readAll();

    QFile file("map.zip");
    file.open(QIODevice::WriteOnly);
    QDataStream out(&file);
    out<<qcompress(ba);

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Compress

    As I said qCompress doesn't use zip but gzip. For zip compression you have to use libzip or an external application like (pk)zip/winzip/whatever.

  8. #8
    Join Date
    Oct 2007
    Location
    Bangalore
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compress

    How to use libzip or external Application in my code .... Please let me know in detail...

  9. #9
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Compress

    I can highly recommend OSDaB zip
    Your pro file should include the following.
    Qt Code:
    1. # set includepath to 3rdparty so we will find <zlib/zlib.h>
    2. INCLUDEPATH += $(QTDIR)/src/3rdparty/
    3. ...
    4. HEADERS += OSDaB/unzip.h
    5. SOURCES +=OSDaB/unzip.cpp
    To copy to clipboard, switch view to plain text mode 
    The zlib functionality should already be linked in with the Qt library. Otherwise there is a usage example on the OSDaB page mentioned above.

  10. #10
    Join Date
    Oct 2007
    Location
    Bangalore
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compress

    Hi,,

    Thank you very much...

  11. #11
    Join Date
    Mar 2012
    Posts
    13
    Thanks
    1
    Qt products
    Qt4

    Default Re: Compress

    How do I decompress the zip file generated which doesn't have header information ?

  12. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Compress

    Another five year old thread resurrected to ask essentially the same question as in this thread

    If you mean a PKZIP file that has no headers then you have a corrupt file and you cannot decompress it.
    If you mean something else you will have to explain.
    Last edited by ChrisW67; 15th April 2012 at 10:34.

  13. #13
    Join Date
    Mar 2012
    Posts
    13
    Thanks
    1
    Qt products
    Qt4

    Default Re: Compress

    I used this chunk to create a zip file. I have linked zlib to my compiler. I could create zip file but not able to decompress it the same way. I am able to create a file with a original extension but nothing is being written to it after decompression. The code used for compression is
    QFile inFile("x.x");
    inFile.Open(QIODevice::ReadOnly);
    QByteArray ba=inFile.readAll();

    QFile file("xx.zip");
    file.open(QIODevice::WriteOnly);
    QDataStream out(&file);
    out<<qCompress(ba);

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Compress

    No, you didn't create a zip file, you created a file with a .zip extension containing some deflated and serialized binary data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Mar 2012
    Posts
    13
    Thanks
    1
    Qt products
    Qt4

    Default Re: Compress

    wysota : How will I be able to decompress it and save it as it was before compression ( I mean to say lossless )

Similar Threads

  1. Compress and Uncompress large files in QTcpSocket
    By vishesh in forum Qt Programming
    Replies: 4
    Last Post: 26th June 2007, 22:21

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.