TLS initialization failed on GET Request

On Windows if you install Qt via online installer, you can select OpenSSL Toolkit as an optional component. This should provide you with the version definitely compatible with your Qt.

If you haven't checked it during installation, you can rerun C:\Qt\MaintenanceTool.exe and select Add or remove components. OpenSSL Toolkit is located under the Developer and Designer Tools section, it is the last entry.

However, there's a note in the sidebar:

Qt installer doesn't set up OpenSSL environment. User needs to define the path and environment variables.

So once installed, you should add the directory with the DLLs to the PATH environment variable or place the needed DLLs near the .exe file (copy them to the debug and release directories of your project).

The directory is located at C:\Qt\Tools\OpenSSL\Win_x64\bin (or Win_x86 if you need 32-bit version). The DLLs are named libssl-1_1-x64.dll and libcrypto-1_1-x64.dll in my case.


But this wasn't enough to deploy it to another machine, after copying it all I got the same error again. The reason came out to be that OpenSSL DLLs depend on another MSVC runtime version than the Qt app itself, and these errors go unreported. Open these DLLs in Dependency Walker to find out what's missing. In my case it was MSVCR100.dll, so I had to install MSVC 2010 Redistributable x64 (x86 is here).


The SSL libraries are not found. The error can be read out in the Qt Src. Either deploy them with your application or install OpenSSL on your machine.

Also, just a small hint:

void MainWindow::replyFini(QNetworkReply* reply)
{
    QString answer = QString::fromUtf8(reply->readAll());
    qDebug() << "answer------------>"<<answer;
}

You should call reply->deleteLater();

void MainWindow::on_btn_login_clicked()
{
    QNetworkRequest request(QUrl("https://httpbin.org/get"));
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFini(QNetworkReply*)));
    manager->get(request);
}

Add connect(manager, &QNetworkAccessManager::finished, manager, &QNetworkAccessManager::deleteLater);to avoid a memory leak on each click.

Tags:

C++

Json

Qt