PDA

View Full Version : Compress



chethana
3rd October 2007, 09:10
code for How to Compress a File In QT4???

wysota
3rd October 2007, 09:41
Could you give more details? Do you want to use a specific algorithm?

chethana
3rd October 2007, 12:37
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....

wysota
3rd October 2007, 12:59
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().

chethana
3rd October 2007, 13:05
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...

chethana
3rd October 2007, 13:18
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);

wysota
3rd October 2007, 13:37
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.

chethana
4th October 2007, 06:46
How to use libzip or external Application in my code .... Please let me know in detail...

spud
4th October 2007, 10:06
I can highly recommend OSDaB zip (http://osdab.sourceforge.net/snippets/zip.php?mode=advanced)
Your pro file should include the following.


# set includepath to 3rdparty so we will find <zlib/zlib.h>
INCLUDEPATH += $(QTDIR)/src/3rdparty/
...
HEADERS += OSDaB/unzip.h
SOURCES +=OSDaB/unzip.cpp

The zlib functionality should already be linked in with the Qt library. Otherwise there is a usage example on the OSDaB page mentioned above.

chethana
5th October 2007, 12:42
Hi,,

Thank you very much...

CodeHunt
15th April 2012, 06:31
How do I decompress the zip file generated which doesn't have header information ?

ChrisW67
15th April 2012, 11:15
Another five year old thread resurrected to ask essentially the same question as in this thread :confused:

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.

CodeHunt
15th April 2012, 16:39
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);

wysota
15th April 2012, 16:46
No, you didn't create a zip file, you created a file with a .zip extension containing some deflated and serialized binary data.

CodeHunt
25th April 2012, 15:14
wysota : How will I be able to decompress it and save it as it was before compression ( I mean to say lossless )