I get the following error when I try to run my Qt application:
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
qt.net
Here is the solution (that worked for me):
The answers definitely work, but you have to find a nearly exact match of the OpenSSL library that your Qt app requires.
This may not be easy. For various reasons, the guy at https://slproweb.com/products/Win32OpenSSL.html seems to be particularly adamant about not supporting older versions of OpenSSL.
I get the point; it really does make sense, but in our case, it was a server side component that did a "Get" to a well known public https location, one single URL only. (An API). There's no real vulnerability with older versions, IMHO, but I realize that is certainly not be true for every app.
What my fix was, was to open up the app in the Visual Studio debugger. (Any debugger that shows demand load DLL's will work). I then hit "Run".
I found that our app, recently compiled by the way, loaded OpenSSL from "Folding at Home" despite the fact I had loaded every version of OpenSSL (and verified the path location) on our test box. Wouldn't run.
On my Dev box, I had NEVER loaded OpenSSL, yet the code ran fine.
I added the line of code that @Fareanor suggested (Upvote his answer also!):
qDebug() << QSslSocket::sslLibraryVersionString();
Our code said: OpenSSL Version needed: "OpenSSL 1.0.2p 14 Aug 2018"
Our code on my Dev box was demand loading:
C:\Program Files (x86)\FAHClient\SSLEAY32.dll
Yours may vary.
The FAH client was version 1.0.2o, or DLL module version: 1.0.2.15. The oldest version from the web site was: 1.0.2.21 and would NOT load even if placed directly in the run location (which is always checked before PATH locations).
Once I copied the OpenSSL files from Folding at Home, to the Prod box from my Dev box, suddenly OpenSSL started working in our code.
We also needed these files: libgcc_s_dw2-1.dll libgcc_s_dw2-1.dll libwinpthread-1.dll zlib1.dll
and those are not documented
Our code is based on an open source project that bundled the Qt library build in a separate "SDK" directory. I found the cmake scripts wouldn't run with VC 2019, or even a patched version of VC 2017, so we've been very reticent to upgrading the QT in it.
Hopefully, if you "do the right thing" and download Qt and build from their sources, you'll be able to bundle a newer OpenSSL with your app. I just wish that were slightly better documented in the Qt side. To be fair, if you do some digging they do mention you'll need OpenSSL, but it's not obvious.
In the event you're trying to get an app running and don't have, or can't upgrade to newer source, this method will at least tell you where the app is getting OpenSSL from.
== John ==
Based on the information provided on the question, it looks like you have installed a too recent OpenSSL version. In fact I already had the same issue.
As you've found out, Qt does not embed OpenSSL. What you have to do is to install it by yourself. But you should ensure that you have the same (or the closest) version of OpenSSL than the one used for the Qt build.
qDebug() << QSslSocket::sslLibraryBuildVersionString();
qDebug() << QSslSocket::supportsSsl();
qDebug() << QSslSocket::sslLibraryVersionString();
Note: Don't forget to include the install directory to the PATH environment variable to make the dlls accessible (or copy the dlls).
Let me know if it does not solve your issue so that I can remove this answer to avoid unnecessary noise.