2017-04-25 22 views
0

我的目標是使用QNetworkRequestQNetworkAccessManager通過SSL連接從網頁獲取源代碼(或圖像)。如何在Windows上爲Qt安裝OpenSSL 1.1.0?

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: 我發現this ARTIKEL和OpenSSL 1.1.0將使用Qt來工作5.10但Qt 5.8中沒有我正在使用的東西。 並在​​Artikel我發現了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文件夾並將libeay32-xxx.dllssleay32-xxx.dll複製到應用程序文件夾,並將文件重命名爲libeay32.dllssleay32.dll。謝謝@ [Max Go]。

現在SSL連接finaly可以工作,但是當我關閉應用程序並且在運行時使用了web連接時,我收到一條錯誤消息。

異常在0x000000007772D1CB(NTDLL.DLL)在onlineTest.exe: 0000005:訪問衝突讀取位置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 *
+2

您正在嘗試複製openssl的靜態庫,但Qt需要dll –

+0

據我所知,Qt靜態構建在MSVC 2015和2017下破壞:(您的問題可能與OpenSSL無關。刪除網絡代碼,看看它是否仍然崩潰。 –

+0

@KubaOber我的代碼工作發現與MSVC 2015和正常網絡(http)。但是,因爲我將'libeay32.dll'和'ssleay32.dll'添加到應用程序文件夾中,所以通過退出應用程序來解決這些崩潰問題。 – Darkproduct

回答

2

下面是我用它來構建OpenSSL的自動從Visual腳本Studio提示。它將構建一個32位或64位庫,具體取決於啓用的編譯器。

先決條件(必須在PATH):

  • 活躍的Perl
  • 7zip的
  • NASM
  • 的Visual Studio 2015年或2017年
  • JOM(我沒有與任何其他測試) (可選)
:: 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 
+1

我認爲這應該適用於Qt 5.8的openSSL 1.0.2h。我手工安裝它,它的工作原理,但不幸的是,我有另一個問題... – Darkproduct