TLS initialization failed ssl error in qt

I use some of the OpenSSL lib’s RSA encryption/decryption features so I installed the recent OpenSSL lib 1.1.0 and inserted the lib into my Qt project. I believed my Qt was activated until I came across this error: QSslSocket::connectToHostEncrypted: TLS initialization failed

Reason behind TLS initialization failed:

I looked for a response on the internet and received this post. I printed the QSslSocket outcome in my program::supportsSl) (and discovered it to be wrong, which meant that QSslSocket did not support SSL yet. It’s a bit strange because I added the OpenSSL lib to my project and implemented the OpenSSL DLL to the application directory, and my software was working well with the lib. Why is QSslSocket not supported by the imported OpenSSL?

I discovered that my Qt was constructed using the 1.0.2b openssl. That’s why the issue is caused. Qt was constructed using an old version of OpenSSL while I was adding the project’s recent version of OpenSSL. Between the two versions, the dll names have changed.

Check: Top Most loved and Hated Programming Language in 2019

The solution of TLS initialization failed step by step:

1- Firstly you need to find your SSL version for your windows machine( SSL version strictly depends on QT versions) with this function:

qDebug() << QSslSocket::supportsSsl() << QSslSocket::sslLibraryBuildVersionString() << QSslSocket::sslLibraryVersionString();

Place this code before calling the QT networks libraries as shown in the screenshot below:

Screenshot (89)

2- After that run your code and call the above function. It will print your required SSL version in application output. In my case, it was “OpenSSL 1.0.2p 14 Aug 2018” “” which may be different for all the users.

TLS initialization failed ss90

3- TLS initialization failed: Now Download the requires SSL libraries from the link given below:

SSL/Archive

Note: Please do not download pre-compiled SSL libraries as it will not going to work.

TLS initialization failed download ssl lib

4- Now check the default file path of your QT application project. In my case it is

C:/Users/risha/Documents/lyricpad-master/build-lyricspad-Desktop_Qt_5_12_3_MinGW_32_bit-Debug/debug/
TLS initialization failed check the path

5- TLS initialization failed: Now extract the zip file and copy all the files of SSL into the build folder of your project. (By default it is found in the same location where you created your project files) In my case it is like:

C:\Users\risha\Documents\lyricpad-master\build-lyricspad-Desktop_Qt_5_12_3_MinGW_32_bit-Debug\debug
extracted folder

6- Paste all the files/content of SSL folder (which you have extracted) into the build directory inside the debug folder. for eg: In my case it is

C:\Users\risha\Documents\lyricpad-master\build-lyricspad-Desktop_Qt_5_12_3_MinGW_32_bit-Debug\debug
 paste the libraries

TLS initialization failed: Now build and run your Qt application now the application will run smoothly.

Problem is solved

If you find any problem in it, then feel free to drop your comments below: