如何将 zlib 添加到现有的 qt 安装中
如何将 zlib 添加到 Qt 的现有安装中。我对此很陌生,所以请给我详细的描述! 提前感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
zlib 包含在 Qt 核心库中。如果你想在 Qt 程序中使用 zlib 函数,你只需要包含 src/3rdparty/zlib 中的 zlib.h 即可。例如,请参见 src/corelib/tools 中 QByteArray 的实现。
如果您想使用 quazip,只需将库添加到您的项目中即可。它基于 Qt 库。请注意构建与您的 Qt 安装相对应的正确 qyazip 库。
通过将以下行添加到项目文件中,您可以获得正确的包含路径:
对于 Qt5,请参阅 Thorbjørn 的评论:使用
#include
就足够了。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:
For Qt5, see Thorbjørn's comment: it is sufficient to use
#include <QtZlib/zlib.h>
.目前的答案仅对Qt4有效。从 Qt5 开始,zlib 头文件存储在不同的目录中。使用 qmake 属性
QT_INSTALL_HEADERS
您可以添加到您的 .pro 文件:INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib
如果您将其添加到quazip.pro
属性
$$[QT_INSTALL_HEADERS]
指向QTDIR/qtbase/include/
,其中包含 QtZlib/zlib.h。在不更改包含路径的情况下,您必须将每个包含语句更改为
#include
正如 Thorbjørn 所评论的那样。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 toQTDIR/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.如果您想使用 zlib 进行压缩/解压缩,请使用 qCompress/qUncompress。
If you want to use zlib for compression/uncompression, use qCompress/qUncompress.
至少这里有些人想要构建 Quazip,这需要 zlib。
以下是我在 Windows 上使用 quazip 0.4.3 执行此操作的方法。
首先在 quazip.pro 中,我将 SUBDIRS 更改为仅包含:
然后我从以下位置下载了 zlib 二进制文件和源代码:
http://www.winimage.com/zLibDll/zlib125dll.zip [二进制文件]
http://www.winimage.com/zLibDll/zlib125.zip [来源]
两者链接来自 http://zlib.net
然后在子文件夹 quazip/quazip.pro 中添加:
在 win32 {}我评论了这一行:
我将 LIBS 行修改为:
我还在 zip.c 和 unzip.c 中修改
为:
之后我将其构建为发布模式并获取了 DLL。
然后在使用它的项目中,我添加了以下配置:
并且可以构建并运行,但仅在测试应用程序的发布模式下。在调试模式下,我收到断言错误并且失败。
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:
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:
in the win32 {} section I commented this line:
and I modified the LIBS line to this:
I also modified in zip.c and unzip.c the
to become:
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:
And that builds and works, but only in Release mode for the test app. In Debug mode i get assertion errors and it fails.