简体   繁体   English

QSslSocket和supportsSsl()返回false

[英]QSslSocket and supportsSsl() returns false

Background 背景

Basically I need a Openssl support for my application, preferably through dynamic linking. 基本上,我需要为我的应用程序提供Openssl支持,最好是通过动态链接。 For this I have complied the Openssl libraries using the following: 为此,我使用以下代码编译了Openssl库:

perl configure VC-WIN32 no-asm --prefix=C:\Build-OpenSSL-VC-32
nmake -f ms\ntdll.mak
nmake -f ms\ntdll.mak test
nmake -f ms\ntdll.mak install

using VC 2017 x86 all tests passed. 使用VC 2017 x86并通过了所有测试。 So far so good. 到现在为止还挺好。 Then I compiled qt5 from source using the following configuration: 然后我使用以下配置从源代码编译了qt5:

configure -debug-and-release -opensource -nomake examples -nomake tests -confirm-license --prefix="C:\Work\qt-bin-5.9-VC-17" -skip webengine -platform win32-msvc -openssl -I C:\Build-OpenSSL-VC-32\include -L C:\Build-OpenSSL-VC-32\lib

The build process succeeded with VC 2017. After this I installed the latest version of qt-creator. VC 2017成功完成了构建过程。此后,我安装了最新版本的qt-creator。 Then I configured the qt versions/kits and paths to the newly complied version. 然后,我配置了qt版本/工具包和新编译版本的路径。 No other versions are installed on this computer. 此计算机上未安装其他版本。 Next I created a small program to test if everything is working properly. 接下来,我创建了一个小程序来测试一切是否正常。 This resulted in QSslSocket::sslLibraryBuildVersionString() returning OpenSSL 1.0.2l 25 May 2017 (version I compiled) and QSslSocket::supportsSsl() returning false. 这导致QSslSocket :: sslLibraryBuildVersionString()返回OpenSSL 1.0.2l,2017年5月25日(我编译的版本)和QSslSocket :: supportsSsl()返回false。 Note I have included: 注意我包括:

 QT       += network
 INCLUDEPATH += C:\Build-OpenSSL-VC-32\include
 LIBS += C:\Build-OpenSSL-VC-32\lib\libeay32.lib
 LIBS += C:\Build-OpenSSL-VC-32\lib\ssleay32.lib

in the .pro file. 在.pro文件中。 I've tried adding the .dll instead of the .lib files but I then get the following error. 我尝试添加.dll而不是.lib文件,但是随后出现以下错误。

C:\Build-OpenSSL-VC-32\bin\libeay32.dll:-1: error: LNK1107: invalid or corrupt file: cannot read at 0x2B8

I would really appreciate any help and information about what I did wrong. 对于我做错了的任何帮助和信息,我将非常感谢。

It is normal to have an error when you replace the ".lib" by the ".dll", you cannot link directly to a dll. 当您用“ .dll”替换“ .lib”时出现错误是正常的,您不能直接链接到dll。 You must link to a ".lib", the ".dll" will be required at execution. 您必须链接到“ .lib”,执行时将需要“ .dll”。 But you should not have to link directly to OpenSSL when building your own app, Qt will load them at run-time when they are needed. 但是在构建自己的应用程序时,您不必直接链接到OpenSSL,Qt会在需要时在运行时加载它们。

QSslSocket::sslLibraryBuildVersionString() returns the version of the SSL library used when you built Qt. QSslSocket::sslLibraryBuildVersionString()返回构建Qt时使用的SSL库的版本。

You need to use QSslSocket::sslLibraryVersionString() to get the version number of the run-time SSL library. 您需要使用QSslSocket::sslLibraryVersionString()来获取运行时SSL库的版本号。 QSslSocket::supportsSsl() gives info about SSL support at run-time, which may not be available even if SSL support was available when you built Qt itself. QSslSocket::supportsSsl()在运行时提供有关SSL支持的信息,即使您构建Qt本身时可以使用SSL支持,该信息也可能不可用。

From what you described, it seems that your program fails to find the OpenSSL dll at run-time. 从您的描述来看,您的程序似乎在运行时找不到OpenSSL dll。 Be sure to place libeay32.dll and ssleay32.dll next to your exe file or in your PATH. 确保将libeay32.dllssleay32.dll放在exe文件旁边或PATH中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM