1

我的目标是QNetworkRequest使用QNetworkAccessManager.

OpenSSL 1.1.0 不适用于 Qt 5.8!在编辑 2 中查找安装解决方案!

第一次尝试:获取 ssleay32.lib 和 libeay32.lib 并将它们复制到调试和发布文件夹中。不要工作。

第二次尝试:(因为是废话而删除)但它不再起作用了。

代码(适用于普通 http):

QUrl url = QUrl(name);
data.clear();

QNetworkRequest *request = new QNetworkRequest(url);
request->setRawHeader("User-Agent", userAgent);

QSslConfiguration sslConfiguration(QSslConfiguration::defaultConfiguration());
request->setSslConfiguration(sslConfiguration);

reply = webCtrl->get(*request);

connect(webCtrl, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
connect(reply, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));

错误信息:

qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_new
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
Error creating SSL context ()

编辑 1: 我发现这个Artikel 和 OpenSSL 1.1.0 将与 Qt 5.10 一起使用,但不适用于我正在使用的 Qt 5.8。在这篇文章中,我找到了QSslSocket::sslLibraryBuildVersionString()命令,我需要 OpenSSL 版本:OpenSSL 1.0.2h 3 May 2016

稍后我将检查另一个 OpenSSL 版本并编辑这篇文章是否正常工作。

编辑 2: 下载OpenSSL 1.0.2h 3 May 2016并安装 7zip 和 Perl。提取 openSSL 文件夹并按照INSTALL.W64. 转到文件夹并将和bin复制到应用程序文件夹并将文件重命名为和。谢谢@[Max Go]。libeay32-xxx.dllssleay32-xxx.dlllibeay32.dllssleay32.dll

现在 SSL 连接终于可以工作了,但是当我关闭应用程序并且在运行时使用了 Web 连接时,我收到了一条错误消息。

onlineTest.exe 中 0x000000007772D1CB (ntdll.dll) 的异常:0xC0000005:访问冲突读取位置 0x0000000000000074。

VS2015 调试窗口“mem.c”第 443 行:

  1. free_debug_func 0x0000000000000000 void(*)(void *, int)
  2. free_func 0x000007fee778b1ba {libeay32.dll!free} void(*)(void *)
  3. str 0x0000000002500cf0 void *

编辑3: 我忘了编译-d debug .dll。只需将编译器模式更改为 Debug,生成 Debug .dll,如果需要不带 -d 的情况下重命名,然后将 debug .dll 复制到 debug 文件夹,将普通 .dll 复制到 release 文件夹。

4

1 回答 1

4

这是我用来从 Visual Studio 提示符自动构建 OpenSSL 的脚本。它将构建 32 位或 64 位库,具体取决于启用的编译器。

先决条件(必须在 PATH 中):

  • 活动 Perl
  • 7zip
  • NASM
  • Visual Studio 2015 或 2017(我没有用其他任何东西进行测试)
  • 乔姆(可选)
:: Configurable Options
:: If you have jom available, set it to jom - it speeds up the build.
@set JOM=nmake
:: Choose a static or dynamic build
@set LIBTYPE=dynamic
:: OpenSSL version in the 1.0.2 series
@set SRC=openssl-1.0.2k

@if "%VSCMD_ARG_TGT_ARCH%"=="x86" (
    @set BITS=32
    @set DST=OpenSSL-Win32
    @set CONFIG=VC-WIN32
    @set SETUP=ms\do_nasm
) else if "%VSCMD_ARG_TGT_ARCH%"=="x64" (
    @set BITS=64
    @set DST=OpenSSL-Win64
    @set CONFIG=VC-WIN64A
    @set SETUP=ms\do_win64a
) else goto no_vscmd

@if "%LIBTYPE%"=="static" (
    @set LIBTYPE=nt
) else if "%LIBTYPE%"=="dynamic" (
    @set LIBTYPE=ntdll
) else goto no_libtype

@echo Building %SRC% for %BITS% bits.

@echo - Downloading
@perl ^
    -e "use LWP::Simple;" ^
    -e "mirror('https://www.openssl.org/source/%SRC%.tar.gz', '%SRC%.tar.gz');"

@echo - Decompressing
@if not exist %SRC%.tar.gz goto no_archive
@rmdir /S /Q %SRC% %DST% 2>NUL
@7z x -bsp2 -y %SRC%.tar.gz >NUL && ^
7z x -bsp2 -y %SRC%.tar     >NUL && ^
del %SRC%.tar
@if errorlevel 1 goto unpack_failed
@if not exist %SRC% goto no_source

@echo - Building
@pushd %SRC%
@perl Configure %CONFIG% --prefix=%~dp0..\%DST% && ^
call %SETUP% && ^
nmake -f ms\%LIBTYPE%.mak init && ^
%JOM% -f ms\%LIBTYPE%.mak "CC=cl /FS" && ^
%JOM% -f ms\%LIBTYPE%.mak test && ^
nmake -f ms\%LIBTYPE%.mak install || goto build_failed
@popd
@rmdir /S /Q %SRC%

@echo Build has succeeded.
@goto :eof

:no_libtype
@echo Error: LIBTYPE must be either "static" or "dynamic">&2
@exit /b 1    

:no_archive
@echo Error: can't find %SRC%.tar.gz - the download has failed :(>&2
@exit /b 1

:unpack_failed
@echo Error: unpacking has failed.>&2
@exit /b %errorlevel%

:no_source
@echo Error: can't find %SRC%\>&2
@exit /b 1

:build_failed
@echo The build had failed.>&2
@popd
@exit /b 2

:no_vscmd
@echo Use vcvarsall x86 or vcvarsall x64 to set up the Visual Studio>&2
@echo build environment first.>&2
@exit /b 100
于 2017-04-25T13:31:24.283 回答