PDA

View Full Version : Can you extract a tarball with Qt?



jshafferman
8th December 2010, 23:05
I was wondering if there was a way to read in a tarball (e.g. file.tar.gz) with Qt? What I would like to be able to do is the user clicks on a tarball and Qt extracts the information, looks for a file in the extracted directory, and loads it without the user having to do anything other then select Open (from the main window) and select the tarball.

Thanks for any help!

ChrisW67
8th December 2010, 23:26
C++ can do these things.

Aside from the obvious basic file manipulation, Qt may be able to help with uncompressing the TAR file, see qUncompress (http://doc.trolltech.com/latest/qbytearray.html#qUncompress). The expected uncompressed size is the last four bytes of the gzip file. There is no QUnpackATarball class unless you care to write it.

Edit: It seems from a second reading you would be happy to actually extract the file to a temporary location and then open the relevant file. You can use Qt to launch system commands (QProcess) to do the unpacking and directory traversal (QDir and QFile). This makes your program platform specific though: GNU tar, or gunzip and another tar won't exist on Windows unless you provide them.