View Full Version : Zipping a .txt file in Qt
croussou
23rd February 2012, 13:50
Hi there,
I have a simple application in Qt where the user enters data in a text file, which is then saved on desktop. After that I would like to be able to insert the .txt file in a .zip file.
I have tried to use QuaZIP with no success, it seems too complicated to understand.
Any help or suggestion would be greatly appreciated.
Thank you in advance.
Kind Regards,
croussou
Le_B
23rd February 2012, 14:19
didn't know about this wrapper, but you can directly use zip.h in minizip from zlib
it s not that hard and there's is exemples that you can use
croussou
23rd February 2012, 14:25
Thank you for replying.
Any available examples that you can share?
Le_B
23rd February 2012, 14:28
here is the api web page:
http://www.winimage.com/zLibDll/minizip.html
and you can find an example of an email writter that use zip for the attached files:
http://www.winimage.com/zLibDll/mapizip_demo_gooddll.zip
Lesiok
23rd February 2012, 16:39
We are using QuaZIP. What is a real problem ?
croussou
23rd February 2012, 19:02
Can you please give an example zipping a simple text file using QuaZIP?
Lesiok
24th February 2012, 06:50
This method packs list of files :
bool MyPacker::packFiles( QString zip_name, QFileInfoList files )
{
QuaZip( zip_name );
zip.setFileNameCodec("Windows-1250");
if( !zip.open( QuaZip::mdCreate ) )
{
return QString();
}
QFile inFile;
QuaZipFile outFile(&zip);
char c;
int j = 0;
foreach(QFileInfo fileInfo, files)
{
if (!fileInfo.isFile())
continue;
inFile.setFileName( fileInfo.absoluteFilePath() );
if (!inFile.open(QIODevice::ReadOnly))
{
return QString();
}
if (!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileInfo.fileName(), fileInfo.filePath())))
{
return QString();
}
while (inFile.getChar(&c) )
outFile.putChar(c));
if (outFile.getZipError() != ZIP_OK)
{
return false;
}
outFile.close();
if (outFile.getZipError() != ZIP_OK)
{
return false;
}
inFile.close();
}
zip.close();
if (zip.getZipError() != 0)
{
return false;
}
return true;
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.