How to manage zip file
-
Hi. I'm trying to use quazip.
I have built quazip package without problem. When I try to runJlCompress::extractDir("a.zip", ".");
the probgram goes to crash.
.pro
windows { INCLUDEPATH += C:/Users/Denis/git/ControlloAccessi/quazip-0.7.2 INCLUDEPATH += C:/Users/Denis/git/ControlloAccessi/zlib128-dll/include LIBS += C:/Users/Denis/git/ControlloAccessi/quazip-0.7.2/quazip/release/quazip.lib }
main.cpp
#include "quazip/quazip.h" #include "QFile" #include "QDebug" #include <quazip/JlCompress.h> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); JlCompress::extractDir("a.zip", "b"); }
-
@mrdebug said in How to manage zip file:
When I try to run
You are linking to the release version of quazip so make sure you run the release version of your app.
change
LIBS += C:/Users/Denis/git/ControlloAccessi/quazip-0.7.2/quazip/release/quazip.lib
intoCONFIG(debug, debug|release) { LIBS += -L"C:/Users/Denis/git/ControlloAccessi/quazip-0.7.2/quazip/debug" LIBS += -lquazipd }else { LIBS += -L"C:/Users/Denis/git/ControlloAccessi/quazip-0.7.2/quazip/release" LIBS += -lquazip }
Also make sure you make both Quazip.dll and zlib.dll (if you did not compile it as static) available at runtime
-
yes with http://quazip.sourceforge.net/classQuaZip.html#ae52ebadd5ce64cdb49d7e198904b0b8c
create aQDataStream
operating on theQByteArary
and then passQDataStream::device()
to that constructor.On the other hand, I'm not sure what you are trying to do but you might not need QuaZip at all, have a look at http://doc.qt.io/qt-5/qbytearray.html#qCompress and below
-
QuaZipFile
represents a file inside a zip file, not a zip file in itself. the constructor you are calling is this one: http://quazip.sourceforge.net/classQuaZipFile.html#a1349ad27f1947bc3e346d83dbf9586c4 useQuaZip
instead.P.S.
QDataStream BufferIn(&Source, QIODevice::ReadOnly);
is the same asQDataStream BufferIn(Source);
-
Hi,
What do you have in QBABufferOut ?
Are you sure it's opened correctly ?
Why do you needBufferIn
for ?And most important, what do you mean by
does not seem to work
? That's to vague to help you. -
Please have a look at this sequence:
QuaZipFile quaZip(QBABufferOut); // (rapresents a zip archivie in ram). if (quaZip.open(QIODevice::ReadOnly)) { // QIODevice::ReadOnly or someting else qDebug() << "ok"; } else qDebug() << "error"; // always error!!!!!!!!!!!!
-
You have to open the QuaZip for decompression first:
QBuffer storageBuff(&QBABufferOut); QuaZip zip(&storageBuff); if (!zip.open(QuaZip::mdUnzip)) qDebug() << "error"; QuaZipFile file(&zip); for (bool f = zip.goToFirstFile(); f; f = zip.goToNextFile()) { QuaZipFileInfo fileInfo; file.getFileInfo(&fileInfo); qDebug() << fileInfo.name; file.open(QIODevice::ReadOnly); qDebug() << "Content: " << file.readAll().toBase64(); file.close(); } zip.close();
P.S.
// (rapresents a zip archivie in ram).
No it doesn't. As mentioned before QuaZipFile represent a file inside a zip archive, not the archive itself
-
@SPlatten said in How to manage zip file:
Is there a license associated with the use of this?
-
@SPlatten if both ends are in your software I'd suggest agains using 3rd party library. qCompress and qUncompress work just fine in that regard. My usual approach is to supply a header (using QDataStream) with checksum and whatever else is needed, then stream to it output from compression routine. Works sufficiently well, eliminates the need for another dependency.
-
-
-