Use OpenSSL in Qt C ++

I got a sample projct that uses QSslSocket and QSslCertificate to get information from SSL certificate (Qt 5.7, Windows 10). The QSslSocket::supportsSsl() function returns false, and I get these errors at runtime:

 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 

So, I compiled OpenSSL_1.1.0 and linked it to my project:

 INCLUDEPATH += . "C:/OpenSSL-Win32/include/" LIBS += -L"C:/OpenSSL-Win32/lib/" -llibcrypto -llibssl 

But all the same mistakes. I downloaded the OpenSSL installer and still the same.

Weird is QSslSocket::sslLibraryBuildVersionString() returns OpenSSL 1.0.2g 1 Mar 2016 , although I compiled and installed OpenSSL_1.1.0.

I know that I do not have enough simple information. Please tell me what it is. Thanks.

+3
c ++ ssl qt openssl
source share
1 answer

From the documentation:

QSslSocket::sslLibraryBuildVersionString() Returns the version string of the SSL library used at compile time. (highlighted by me)

Just because you get the result from it does not mean that Qt has access to OpenSSL, just that it was compiled with a specific version. This allows you to find out which binary compatible version you should provide at runtime if it is dynamically linked (as by default).

You want to check QSslSocket::sslLibraryVersionNumber() - [...] the version of the library used at runtime (my selection).

Qt will apparently try to find a copy of the OpenSSL DLL in PATH , and if not, in the paths given by QCoreApplication::libraryPaths . You must add the location of the OpenSSL DLL to one before attempting to use OpenSSL.

+4
source share

All Articles