How to compress data with Qt?

Qt uses the zlib library to provide compression. This means that you can compress and decompress your bytearrays of data using Qt. See the documentation on qUncompress() [qt.nokia.com]

Note that this does not produce file archives that can be opened by other applications, to do that you will need to write it yourself using Qt’s custom file handling system [qt.nokia.com] or use a 3rd party library.

5 comments

October 18, 2010

Picture of Andre Andre

Mad Scientist

An IMHO useful 3rd party solution is the one by Bugless: http://www.bugless.co.uk/products/archive/archive.html
It works with Qt3 and Qt4, and has a dual GPL + commercial licence.

Also, Nokia itself provides a QtSolution called QtIOCompressor that may be useful: http://qt.nokia.com/products/appdev/add-on-products/catalog/4/Utilities/qtiocompressor/

The difference is that the solution by Bugless can work with complete archives (multiple files compressed into one file in standard WinZip format) while the solution only works on a single file. Both have their uses.

November 25, 2010

Picture of dfaure dfaure

Lab Rat

kdelibs, from the KDE project, also has a QIODevice-subclass called KFilterDev, which can compress/uncompress data in gzip, bzip2 and xz formats, incrementally rather than all-in-one-go. It is relatively self contained in the directory http://websvn.kde.org/trunk/KDE/kdelibs/kdecore/compression/ and therefore easy to extract. And it’s LGPL licensed.

December 5, 2010

Picture of xsacha xsacha

Ant Farmer

It’d be useful if there was an easy Qt compressor that supported encryption or code obfuscation too.

Read this topic for motive: http://developer.qt.nokia.com/forums/viewthread/2153/P15/

Basically, to hide QML files so people can’t simply rip yours and make a competing app.

December 5, 2010

Picture of Andre Andre

Mad Scientist

Should be easy enough to achieve based on the tools mentioned above. You could simply XOR the data with some key. Or you use a crypto class, which is also available for Qt. Sure, you won’t get it 100% secure (ever, I think, since you are supplying the key as well as the data), but it is better than nothing.

December 19, 2010

Picture of Vass Vass

Gene Splicer

http://quazip.sourceforge.net/ – Qt wrapper for zip/unzip

Write a comment

Sorry, you must be logged in to post a comment.