August 19, 2012

Leon Leon
Robot Herder
400 posts

How to unzip a zip file with qt fuction?

 

Is there a way to unzip a zip file with a qt fuction..? ( lets say the zip file has some songs in it )
I have heard about quncompress.. when i tried this:

  1. QFile infile(QDir::homePath()+"/Downloads/ena.zip");
  2.     QFile outfile(QDir::homePath()+"/Downloads");
  3.     infile.open(QIODevice::ReadOnly);
  4.     outfile.open(QIODevice::WriteOnly);
  5.     QByteArray uncompressedData = infile.readAll();
  6.     QByteArray compressedData = qUncompress(uncompressedData);
  7.     outfile.write(compressedData);
  8.     infile.close();
  9.     outfile.close();

an error like this appeared:

  1. qUncompress: Z_DATA_ERROR: Input data is corrupted

4 replies

August 19, 2012

koahnig koahnig
Mad Scientist
2099 posts

The archives have typically some file management involved. That is not part of zlib.
Some useful information you may find here [qt-project.org]


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.

August 19, 2012

Leon Leon
Robot Herder
400 posts

i didn’t want to use something that is not in the default library.. but it seems i will.. i will try to use Quazip.. if i find any difficulties i will post in this thread.. :)

August 20, 2012

Tobias Hunger Tobias Hunger
Mad Scientist
3130 posts

zlib != zip

zip usually does contain meta information about files stored which is not handled at all by qUncompress, which just takes a chunk of memory and returns another chunk that is compressed.

August 20, 2012

matti- matti-
Ant Farmer
107 posts

Go with Quazip.

 Signature 

Author of MMark13

 
  ‹‹ navigation from login form to main window.. any help?      How to abort beginInsertRows()? ››

You must log in to post a reply. Not a member yet? Register here!