Results 1 to 15 of 15

Thread: Compress

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 ?

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.