Qt: QNetworkAccessManager and SSL connection under Windows
QNetworkAccessManager is the Qt component for make network connection. The use of this component is quite easy and you can use for basic operation like download files or web pages. Experimenting the use you'll note it work very well with standard network connection but, especially under Windows, doesn't work with SSL connection (like 'https' for example).
QNetworkAccessManager is already designed to work with SSL connection but the problem is the standard Qt package miss (by default) the require libraries for manage the connection encryption. It seem the problem came from some copyright restrictions that doesn't allow Qt team to distribute required additional libraries with default Qt libraries package. Basically QNetworkAccessManager, if SSL connection detected, look into the current system if these libraries are available for use, if not return the following error:
QNetworkReply::UnknownNetworkError
Checking the error more in details (through errorString()) it return:
Error creating SSL context
Please note, this error doesn't always mean the SSL libraries are missing since encryption process require more steps and if one of these steps fail for some reasons same error could be generated (a common error would be use a incorrect certificate for encryption). The suggestion here, as first step once got this error, is to check if the required SSL libraries are available in the system. If not add it as explained below and try again, if already present the problem came from another reasons. Adding the required libraries is a quite easy operation. In Linux system you need to install the OpenSSL package (however this package is usually already installed by default in all major distributions) but under Windows you need to manually download the dynamic libraries and copy to some path where your Qt executable can find them. There are many sources where you can get ready made precompiled Windows libraries (both 32 and 64 bit version), I suggest this site making available all versions of OpenSSL (in case you are interested in some specific version for various reasons). Once downloaded the version you are interested in (usually the latest) you simply have to extract the copy the two following dynamic libraries:
libeayXX.dll
ssleayXX.dll
Please note the XX refer to your target system type. This mean in case of 32 bit system instead of XX you'll have 32 and, as obvious, 64 for 64 bit system. As already said your Qt executable need to find them than you have various choices regarding where to put the libraries. The best solution for avoid forget to include these libraries in your software distribution is to copy in the same path where is the executable. In alternative you can copy into main Windows system path but you need to have the administration privileges to make such action.
Comments
Post a Comment