[ACCEPTED]-how to add zlib to an existing qt installation-zlib

Accepted answer
Score: 13

zlib is contained in the core Qt libraries. If 12 you want to use the zlib functions in a 11 Qt program, you only have to include zlib.h 10 which is in src/3rdparty/zlib. See e.g. the 9 implementation of QByteArray in src/corelib/tools.

If 8 you want to use quazip, just add the library 7 to your project. It is based on the Qt libraries. Take 6 care to build the correct qyazip library 5 that corresponds to your Qt installation.

You 4 get the correct include path by adding the 3 following line to your project file:

INCLUDEPATH += $$[QT_INSTALL_PREFIX]/src/3rdparty/zlib

For 2 Qt5, see Thorbjørn's comment: it is sufficient 1 to use #include <QtZlib/zlib.h>.

Score: 12

The current answer is only valid for Qt4. Since 8 Qt5 the zlib header file is stored in a 7 different directory. Using the qmake property 6 QT_INSTALL_HEADERS you can add to your .pro file:

INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib

This works 5 e.g. to build quazip, if you add it to quazip.pro

The 4 property $$[QT_INSTALL_HEADERS] points to QTDIR/qtbase/include/ within which lies QtZlib/zlib.h.

Without 3 changing the includepath you have to change 2 every include-statement to #include <QtZlib/zlib.h> as commented 1 by Thorbjørn.

Score: 7

If you want to use zlib for compression/uncompression, use 1 qCompress/qUncompress.

Score: 5

At least some people here want to build 15 Quazip, which requires zlib.

Here's how I 14 did it on windows with quazip 0.4.3.

First 13 in the quazip.pro I changed SUBDIRS to contain 12 only:

SUBDIRS=quazip

Then I downloaded zlib binaries and 11 source from: http://www.winimage.com/zLibDll/zlib125dll.zip [binaries] http://www.winimage.com/zLibDll/zlib125.zip [source]

both links 10 came from http://zlib.net

Then in the subfolder quazip/quazip.pro 9 I added:

INCLUDEPATH += <path to zlib source>

in the win32 {} section I commented 8 this line:

#  *-msvc*: QMAKE_LFLAGS += /IMPLIB:$$DESTDIR\\quazip.lib

and I modified the LIBS line to 7 this:

*-msvc*: LIBS += -lzlibwapi -L<path to zlib binaries>/dll32

I also modified in zip.c and unzip.c 6 the

#include "zlib.h"

to become:

#include <zlib.h>

After that I build this to 5 Release mode and got a DLL out.

Then in the 4 project to use this, I added the following 3 config:

INCLUDEPATH += <quazip source path>
INCLUDEPATH += <zlib source path>

LIBS += -L<quazip source path>\quazip\release -lquazip

And that builds and works, but only 2 in Release mode for the test app. In Debug 1 mode i get assertion errors and it fails.

More Related questions