C++ 如何将 zlib 添加到现有的 qt 安装中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4002757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to add zlib to an existing qt installation
提问by defiant
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!
如何将 zlib 添加到 Qt 的现有安装中。我在这方面很新,所以请给我详细的描述!提前感谢您的帮助!
采纳答案by hmuelner
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.
zlib 包含在核心 Qt 库中。如果你想在 Qt 程序中使用 zlib 函数,你只需要包含在 src/3rdparty/zlib 中的 zlib.h。参见例如 src/corelib/tools 中 QByteArray 的实现。
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.
如果您想使用 quazip,只需将库添加到您的项目中。它基于 Qt 库。注意构建与您的 Qt 安装相对应的正确 qyazip 库。
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>
.
对于 Qt5,请参阅 Thorbj?rn 的评论:使用#include <QtZlib/zlib.h>
.
回答by Johannes Munk
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:
当前答案仅对 Qt4 有效。从 Qt5 开始,zlib 头文件存储在不同的目录中。使用 qmake 属性,QT_INSTALL_HEADERS
您可以将其添加到 .pro 文件中:
INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib
INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib
This works e.g. to build quazip, if you add it to quazip.pro
这适用于例如构建 quazip,如果您将其添加到 quazip.pro
The property $$[QT_INSTALL_HEADERS]
points to QTDIR/qtbase/include/
within which lies QtZlib/zlib.h.
该属性$$[QT_INSTALL_HEADERS]
指向QTDIR/qtbase/include/
QtZlib/zlib.h 所在的位置。
Without changing the includepath you have to change every include-statement to #include <QtZlib/zlib.h>
as commented by Thorbj?rn.
在不更改包含路径的情况下,您必须将每个包含语句更改为 Thorbj #include <QtZlib/zlib.h>
?rn 的评论。
回答by Johannes Munk
If you want to use zlib for compression/uncompression, use qCompress/qUncompress.
如果要使用 zlib 进行压缩/解压缩,请使用qCompress/qUncompress。
回答by Emmanuel Touzery
At least some people here want to build Quazip, which requires zlib.
至少这里有些人想要构建 Quazip,这需要 zlib。
Here's how I did it on windows with quazip 0.4.3.
这是我在带有 quazip 0.4.3 的 windows 上的做法。
First in the quazip.pro I changed SUBDIRS to contain only:
首先在 quazip.pro 中,我将 SUBDIRS 更改为仅包含:
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]
然后我下载了 zlib 二进制文件和来源: http://www.winimage.com/zLibDll/zlib125dll.zip[binaries] http://www.winimage.com/zLibDll/zlib125.zip[source]
both links came from http://zlib.net
两个链接都来自http://zlib.net
Then in the subfolder quazip/quazip.pro I added:
然后在子文件夹 quazip/quazip.pro 我添加:
INCLUDEPATH += <path to zlib source>
in the win32 {} section I commented this line:
在 win32 {} 部分,我评论了这一行:
# *-msvc*: QMAKE_LFLAGS += /IMPLIB:$$DESTDIR\quazip.lib
and I modified the LIBS line to this:
我将 LIBS 行修改为:
*-msvc*: LIBS += -lzlibwapi -L<path to zlib binaries>/dll32
I also modified in zip.c and unzip.c the
我也在 zip.c 和 unzip.c 中修改了
#include "zlib.h"
to become:
成为:
#include <zlib.h>
After that I build this to Release mode and got a DLL out.
之后,我将其构建为发布模式并获得了一个 DLL。
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.
这可以构建并运行,但仅限于测试应用程序的发布模式。在调试模式下,我收到断言错误并且失败了。