Hi,
After I zip my data using the code below, I can create the zip file and it's size is quite logical. But when I attempt to unzip it using WinZip, Winzip gives me an error.
I'm working on Microsoft VS 2O1O and using Qt 4.8.
Any ideas?
QByteArray LoggerManager
::packFiles(const QString
& p_name,
const QByteArray
& p_BytesToBrCompressed
) {
QuaZip zip(testZip);
zip.setFileNameCodec("IBM866"); /* or Windows-1250 */
if(!zip.open(QuaZip::mdCreate))
{
qWarning("testCreate(): zip.open(): %d", zip.getZipError());
return NULL;
}
QString loc
= qApp
->applicationDirPath
() + "/logs/error_log/";
QFileInfoList files
=QDir(loc
).
entryInfoList();
QuaZipFile outFile(&zip);
char c;
if(!outFile.
open(QIODevice::WriteOnly, QuaZipNewInfo
("",
""))) {
qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
return NULL;
}
//while(inFile.getChar(&c)&&outFile.putChar(c));
for(int i=0; i < p_BytesToBrCompressed.size(); i++)
{
outFile.putChar(p_BytesToBrCompressed.at(i));
}
if(outFile.getZipError()!=UNZ_OK)
{
qDebug() << "AQQQQQQQQQQQQQQQQ!!";
qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
return NULL;
}
outFile.close();
if(outFile.getZipError()!=UNZ_OK)
{
qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
return NULL;
}
if(QFile::exists(p_name
)) {
{
compressedData.append(reader.readAll());
}
}
inFile.close();
zip.close();
if(zip.getZipError()!=0)
{
qWarning("testCreate(): zip.close(): %d", zip.getZipError());
return NULL;
}
qDebug() << "Compressed Data: " << compressedData;
return compressedData;
}
QByteArray LoggerManager::packFiles(const QString& p_name, const QByteArray& p_BytesToBrCompressed)
{
QString testZip = p_name;
QuaZip zip(testZip);
zip.setFileNameCodec("IBM866"); /* or Windows-1250 */
if(!zip.open(QuaZip::mdCreate))
{
qWarning("testCreate(): zip.open(): %d", zip.getZipError());
return NULL;
}
QString loc = qApp->applicationDirPath() + "/logs/error_log/";
QFileInfoList files=QDir(loc).entryInfoList();
QFile inFile;
QFile inFileTmp;
QuaZipFile outFile(&zip);
char c;
QByteArray compressedData = "";
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo("", "")))
{
qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
return NULL;
}
//while(inFile.getChar(&c)&&outFile.putChar(c));
for(int i=0; i < p_BytesToBrCompressed.size(); i++)
{
outFile.putChar(p_BytesToBrCompressed.at(i));
}
if(outFile.getZipError()!=UNZ_OK)
{
qDebug() << "AQQQQQQQQQQQQQQQQ!!";
qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
return NULL;
}
outFile.close();
if(outFile.getZipError()!=UNZ_OK)
{
qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
return NULL;
}
QFile reader(p_name);
if(QFile::exists(p_name))
{
if(reader.open(QIODevice::ReadOnly))
{
compressedData.append(reader.readAll());
}
}
inFile.close();
zip.close();
if(zip.getZipError()!=0)
{
qWarning("testCreate(): zip.close(): %d", zip.getZipError());
return NULL;
}
qDebug() << "Compressed Data: " << compressedData;
return compressedData;
}
To copy to clipboard, switch view to plain text mode
Added after 1 24 minutes:
Hi again,
The problem was in;
if(!outFile.
open(QIODevice::WriteOnly, QuaZipNewInfo
("",
"")))
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo("", "")))
To copy to clipboard, switch view to plain text mode
so replacing the above line with;
if(!outFile.
open(QIODevice::WriteOnly, QuaZipNewInfo
("syd_barrett.txt")))
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo("syd_barrett.txt")))
To copy to clipboard, switch view to plain text mode
solved the problem.
Unfortunately in Quazip, there is nothing to alert the user for this case at least.
Anyway, the problem solved and thanks.
Bookmarks