Qt-network.ssl QSslSocket:TLS初始化失败等等问题
在使用QML的时候运行程序的时候遇到了好几次类似以下问题:
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
qt.network.ssl: QSslSocket: cannot resolve DTLSv1_2_server_method
qt.network.ssl: QSslSocket: cannot resolve DTLSv1_2_client_method
qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_CTX_new
qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_CTX_free
qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_CTX_set_ssl_ctx
qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_CTX_set_flags
qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_CTX_finish
qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_cmd
qt.network.ssl: QSslSocket: cannot resolve SSL_set_alpn_protos
qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_alpn_select_cb
qt.network.ssl: QSslSocket: cannot resolve SSL_get0_alpn_selected
qt.network.ssl: QSslSocket: cannot resolve DTLS_server_method
qt.network.ssl: QSslSocket: cannot resolve DTLS_client_method
qt.network.ssl: QSslSocket: cannot call unresolved function DTLS_client_method
————————————————————————————————————————————————
重点来了:最后总结了一下大概可以从以下方法解决:
1、对于Qt mingw版本用户来说
一般在:
C:\Qt\Qt 5.xx.x\Tools\mingw730_32\opt\bin(32位)
或者:
C:\Qt\Qt 5.xx.x\Tools\mingw730_32\opt\bin(64位)
目录(以实际安装路径为准)可以找到 libeay32.dll ssleay32.dll 两个文件
1)复制这两个文件到Qt工程生成可执行文件的目录(即exe文件同目录下)中去,再次运行,错误消失
2)复制这两个文件到C:\Qt\Qt 5.xx.x\Qt 5.xx.x\mingwxxx_xx\bin 的目录下,再次运行,错误消失
可以参考这篇文章:👉 (Qt-network.ssl问题报错)
上方式一般对于mingw版本来说基本可以解决
2、对于Qt MSVC版本用户来说
A、可以随便一个Qt C++工程中打印出openssl版本信息
#include <QSslSocket>
qDebug()<<QSslSocket::sslLibraryBuildVersionString();
5.12.3版本为例,执行打印出 OpenSSL 1.1.1b 26 Feb 2019
B、根据相应版本去下载OpenSSL的二进制文件,当然也可以选择自己编译,只不过有点麻烦
文件下载地址:http://slproweb.com/products/Win32OpenSSL.html
我下载的是Win64 OpenSSL v1.1.1d Light,完了之后安装
C、安装好后在安装目录找到 libcrypto-1_1-x64.dll libssl-1_1-x64.dll 两个文件 ,然后粘贴到
C:\Qt\Qt5.13.0\5.13.0\msvc2017_64\bin目录再次运行,错误消失,完美解决