Qt SSL 支持缺失
我刚刚下载了 Qt(LGPL - Qt SDK for Windows),当我运行一些演示时,他们抱怨 Qt 没有 SSL。
如何获取启用了 SSL 的 Qt SDK?我真的需要从源代码编译它以获得 SSL 支持吗?为什么我下载的版本中缺少它?
I've just downloaded Qt (LGPL - Qt SDK for Windows) and when i run some of the demos they complain about Qt not having SSL.
How can i get the Qt SDK with SSL enabled? Do i really need to compile it from source to get SSL support? Why is it missing in the version i've downloaded?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
@user261882 答案仅部分正确。他正确地说 Qt 不支持 SSL,您确实需要下载 OpenSSL 库。
然而,之后的链接过程要简单得多,您不需要在下载 SSL 库后重建 Qt 或摆弄 Microsoft Visual 的东西。 Qt 让这一切变得简单。
下载 SSL 库后,您需要做的就是确保 Qt 可以找到这些 openSSL 库所在的位置。如果在下载过程中选择将 openSSL DLL 复制到 Windows 系统目录的选项, Qt 将自动在该目录中查找 openSSL 二进制文件,因为 Windows 始终搜索 Windows 系统目录。
如果您不想在 Windows 系统目录中安装 openSSL 库,那也没关系,您只需告诉 Qt openSSL DLL 的位置即可。您可以通过多种方式执行此操作...一种可能的解决方案是将 openSSL DLL 的位置添加到系统路径中。另一个简单的解决方案是将 openSSL DLL 复制到包含可执行文件的目录中。该目录也保证会被搜索到。
您可以稍后运行一个简单的检查,看看这是否有效,即调用静态函数QSslSocket:: supportSsl(),如果此函数返回 true,则 Qt 已找到您下载的 openSSL 二进制文件。(当然,请确保您在
中添加
文件,然后运行此测试)Qt += network
>.pro使用 Qt Creator 2.5.2 和 Win32 OpenSSL 库 v1.0.1c 使用 Qt 4.8.3 二进制文件进行测试
希望这可以为每个人节省一些时间。通过这种方式,您不需要去搜索 Visual Studio 文件,而且要简单得多。
@user261882 answer is only partially correct. He is correct in saying that Qt does not come with SSL support and that you do need to download the OpenSSL libraries.
However, the linking process after is much more simple, you do not need to rebuild Qt after downloading the SSL libraries or mess around with Microsoft Visual stuff. Qt makes it easy for you.
All that you need to do after downloading the SSL libraries is ensure that Qt can find where these openSSL libraries are located. If during your download you select the option to copy the openSSL DLL's to the Windows system directory, Qt will automatically find the openSSL binaries in that directory since the Windows system directory is always searched by Windows.
If you do not wish to install the openSSL libraries in your Windows system directory, that is fine, you just need to tell Qt where the openSSL DLL's are located. You can do this in a number of ways... one possible solution is setting adding the openSSL DLL's location to the system PATH. Another simple solution is to copy the openSSL DLL's into the directory which contains your executable. This directory is guaranteed to be searched as well.
A simple check that you can run afterwards to see if this worked is call the static function QSslSocket::supportsSsl(), if this function returns true, Qt has found the openSSL binaries that you downloaded. (Of course ensure that you add
Qt += network
in your.pro
file before running this test)Tested with Qt 4.8.3 binaries, using Qt Creator 2.5.2, and Win32 OpenSSL libraries v1.0.1c
Hope this saves everyone some time. Doing it this way you don't need to go and search the Visual Studio files and it is much simpler.
要为 Qt 启用 SSL,您首先必须下载 OpenSSL 包。为此,我建议下载此处提供的 OpenSSL 二进制文件。 安装二进制文件并阅读它们附带的帮助。
这部分用于在 Microsoft Visual C++ 下安装 OpenSSL 二进制文件(下面的文本摘自二进制文件的帮助)
设置正确的参数后,您现在可以配置 Qt 以启用 SSL 支持。
运行configure.exe -debug-and-release -webkit -openssl -IC:\openssl\Include -LC:\openssl\Lib,然后运行nmake。您已启用 SSL 支持。不要忘记将 Qt += network 放入您的 .pro 文件中。
这对我和我的同事有用,也应该对你有用:)。
To enable SSL for Qt, you first must download the OpenSSL package. For that I suggest to download the binaries for OpenSSL that are availiable here. Install the binaries and read the help that comes with them.
This part is for installing OpenSSL binaries under Microsoft Visual C++(the text under is taken from the help of the binaries)
After setting the right parameters, you are now ready to configure Qt to enable SSL support.
Run configure.exe -debug-and-release -webkit -openssl -I C:\openssl\Include -L C:\openssl\Lib, and then nmake. You have enabled SSL support. Don't forget to put Qt += network in your .pro file.
That had worked for me and for my colleagues, should work for you too:).
来自 Qt 文档,
如果您已经安装了 OpenSSL,请尝试
在您的
.pro
文件中提供Qt += network
..希望它有帮助..
From Qt Documentation,
If you have already OpenSSL installed, try giving
Qt += network
in your.pro
file..Hope it helps..
QT 5.15:
注意:如果编译 x86 变体,则必须从 Win_x86 文件夹复制 DLL,
我在这里找到了这个答案:https://www.programmersought.com/article/71774817627/
QT 5.15:
NOTE: if you compile x86 variant you have to copy DLLs from the Win_x86 folder.
I found this answer here: https://www.programmersought.com/article/71774817627/