14

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!

menjaraz
  • 7,551
  • 4
  • 41
  • 81
defiant
  • 3,161
  • 11
  • 41
  • 65

4 Answers4

13

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>.

hmuelner
  • 8,093
  • 1
  • 28
  • 39
  • 2
    Thanks for the advice. I have the similar problem, and adding zlib said directory to INCLUDEDIRS makes compilation go okay. Until the linking stage. Linker doesn't know where to look for zlib to link with and neither do I. Please help. – Septagram Dec 16 '10 at 05:45
  • You to not have to link with zlib, the zlib functions are part of QtCore4.dll. – hmuelner Dec 30 '11 at 09:18
  • 5
    As of Qt 5 this directory is normally not available. Fortunately, that line is also no longer necessary since instead zlib.h can be included like this: `#include ` – Thorbjørn Lindeijer Jan 19 '14 at 19:27
  • 2
    After banging my head on this one too, I can vouch that Thorbjørn's answer worked. VS2010 & Qt 5.2.0. – Rob Winchester Jan 20 '14 at 20:47
  • In the similar Question, there is a completely different answer. You shouldn't use the qt internal zlib at all: http://stackoverflow.com/questions/23989823/zlib-in-qt-qtzlib-not-present – transistor Apr 29 '15 at 15:26
12

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.

Johannes Munk
  • 305
  • 2
  • 8
7

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

5

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.

Emmanuel Touzery
  • 9,008
  • 3
  • 65
  • 81