Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. TLS initialization failed
Forum Updated to NodeBB v4.3 + New Features

TLS initialization failed

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 3 Posters 5.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sahak
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sahak
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • SGaistS SGaist

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

            S Offline
            S Offline
            Sahak
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              0
              • SGaistS SGaist

                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.

                S Offline
                S Offline
                Sahak
                wrote on last edited by
                #7

                @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

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  S 1 Reply Last reply
                  0
                  • SGaistS SGaist

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

                    S Offline
                    S Offline
                    Sahak
                    wrote on last edited by
                    #9

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

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

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

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

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      S 2 Replies Last reply
                      1
                      • SGaistS SGaist

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

                        S Offline
                        S Offline
                        Sahak
                        wrote on last edited by
                        #11

                        @SGaist Oh, my excuses.

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

                        1 Reply Last reply
                        0
                        • SGaistS SGaist

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

                          S Offline
                          S Offline
                          Sahak
                          wrote on last edited by
                          #12

                          @SGaist So, now what I need to modify?

                          aha_1980A 1 Reply Last reply
                          0
                          • S Sahak

                            @SGaist So, now what I need to modify?

                            aha_1980A Offline
                            aha_1980A Offline
                            aha_1980
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @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

                            Qt has to stay free or it will die.

                            S 1 Reply Last reply
                            2
                            • aha_1980A aha_1980

                              @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

                              S Offline
                              S Offline
                              Sahak
                              wrote on last edited by Sahak
                              #14

                              @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

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

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

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved