Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

TLS initialization failed



  • Hello! While I was programming in Qt (on Windows 10) I stuck with a problem:

    qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
    

    I downloaded 1.1.1d of OpenSSL, also included OpenSSL-Win32 in PATH, then I tried to include

    INCLUDEPATH += C:/Program Files (x86)/OpenSSL-Win32/include
    

    And nothing have helped me!

    My code:

    /...
    #include <QtNetwork/QNetworkAccessManager>
    #include <QtNetwork/QNetworkReply>
    #include <QtNetwork/QNetworkRequest>
    #include <QtXml/QDomDocument>
    #include <QtXml/QDomNode>
    #include <QUrl>
    
    /...
    
    void log_in::setCurrency()
    {
    
       QNetworkAccessManager *manager = new QNetworkAccessManager(this);
       QNetworkRequest request(QUrl("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"));
       connect(manager, &QNetworkAccessManager::finished, this, &log_in::getResponse);
    qDebug() << QSslSocket::sslLibraryBuildVersionString();
       manager->get(QNetworkRequest(request));
    }
    
    void log_in::getResponse(QNetworkReply *reply)
    {
        QDomDocument domDoc;
    
        if(domDoc.setContent(reply->readAll()))
        {
            QDomNode rootNode = domDoc.documentElement();
            findNode( rootNode, "Cube", "USD");
            findNode( rootNode, "Cube", "RUB");
            findNode( rootNode, "Cube", "GBP");
        }
    
        delete reply;
    }
    
    bool log_in::findNode(const QDomNode &node, const QString &name, const QString &currency)
    {
        if(node.isElement())
        {
            QDomElement element = node.toElement();
            if(element.tagName() == name && element.attribute("currency") == currency)
            {
                QString str;
                str.append(node.firstChildElement("currency").text());
                str.append(" ");
    
                QString str_double(node.firstChildElement("Cube rate").text());
                double rate = str_double.toDouble();
    
                str.append(QString::number(rate, 'f', 2));
                str.append(" €");
    
                if(currency == "USD")
                {
                    ui->dollar_currency->setText(str);
                }
                else if(currency == "RUB")
                {
                    ui->rubles_currency->setText(str);
                }
                else if(currency == "GBP")
                {
                    ui->pounds_currency->setText(str);
                }
    
                return true;
            }
        }
    
        QDomNode siblingNode = node.nextSiblingElement();
    
        while(!siblingNode.isNull())
        {
            bool res = findNode(siblingNode, name, currency);
            if(res)
                return true;
            siblingNode = node.nextSiblingElement();
        }
    
        QDomNode childNode = node.firstChild();
        if(!childNode.isNull())
        {
            bool res = findNode(childNode, name, currency);
            if(res)
                return true;
        }
        return false;
    }
    

    I would like to get help from you.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What version of Qt are you using ?
    Which compiler are you using ?



  • Thank you for welcoming!

    I am using Qt 5.12.6 and I am not really sure, but I think I use msvc2017, because I have in my Qt file msvc2017 and mingw73_32


  • Lifetime Qt Champion

    Then you should double check, because you have to get an OpenSSL build that uses the same compiler.



  • @SGaist My compiler is Desktop(x86-windows-msvc2019_pe_32bit_Debug).


  • Lifetime Qt Champion

    In the Run part of the Project panel, did you also modify the PATH environment variable so the OpenSSL dlls can be found ?

    Do not do that system wide.



  • @SGaist To be honest, I don't really understand what to do.

    Here's a screenshot of the Project panel. Could you please navigate me what to do?

    3735186c-3970-47ce-8c34-6d0c8dc6516b-image.png


  • Lifetime Qt Champion

    Unfold the Run Environment part, you'll have there the variables you can modify.



  • @SGaist Here it is. Now what I need to modify?

    8da80c74-a222-47c0-bd10-54749cd30917-image.png


  • Lifetime Qt Champion

    I meant click on the "Details" arrow under Run Environment.



  • @SGaist Oh, my excuses.

    Here it is f7bd32cc-6e52-4529-81ae-9f3137ff34bd-image.png



  • @SGaist So, now what I need to modify?


  • Lifetime Qt Champion

    @Sahak After you selected the Path variable, you can use Prepend Path to add the path to the libraries (DLLs) to your Path variable. Then at runtime, this directory searched when the DLLs are loaded.

    Regards



  • @aha_1980
    I "Append the path" in PATH, as you see on the screenshot.

    91acfc39-f86b-4c6e-9a8d-44172b29a5e8-image.png

    Then the compiler doesn't work and forcefully finishes the program

    9950bf68-6095-40f6-b096-6771c626e30f-image.png


  • Lifetime Qt Champion

    You application seems to crash, what do you get if running it through the debugger ?


Log in to reply