how to add zlib to an existing qt installation

31,456

Solution 1

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

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

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

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

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

Solution 2

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

INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib

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

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

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

Solution 3

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

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

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

SUBDIRS=quazip

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

both links came from http://zlib.net

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

INCLUDEPATH += <path to zlib source>

in the win32 {} section I commented this line:

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

and I modified the LIBS line to this:

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

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

#include "zlib.h"

to become:

#include <zlib.h>

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

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

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

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

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

Share:
31,456
defiant
Author by

defiant

Updated on January 23, 2020

Comments

  • defiant
    defiant over 4 years

    How can I add zlib to an existing installation of Qt. I m pretty new in this so please give me detailed description! Thanks for your help in advance!