code for How to Compress a File In QT4???
code for How to Compress a File In QT4???
Could you give more details? Do you want to use a specific algorithm?
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....
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().
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...
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);
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.
How to use libzip or external Application in my code .... Please let me know in detail...
I can highly recommend OSDaB zip
Your pro file should include the following.
The zlib functionality should already be linked in with the Qt library. Otherwise there is a usage example on the OSDaB page mentioned above.Qt Code:
# set includepath to 3rdparty so we will find <zlib/zlib.h> INCLUDEPATH += $(QTDIR)/src/3rdparty/ ... HEADERS += OSDaB/unzip.h SOURCES +=OSDaB/unzip.cppTo copy to clipboard, switch view to plain text mode
Hi,,
Thank you very much...
How do I decompress the zip file generated which doesn't have header information ?
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.
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);
No, you didn't create a zip file, you created a file with a .zip extension containing some deflated and serialized binary data.
wysota : How will I be able to decompress it and save it as it was before compression ( I mean to say lossless )
Bookmarks