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 during API call?
Forum Updated to NodeBB v4.3 + New Features

TLS initialization failed during API call?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 4 Posters 6.6k 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.
  • C Offline
    C Offline
    ckzaner
    wrote on last edited by
    #1

    I've used this same code for a project working with the ITunes API and it worked fine. Currently I am trying to work with a crypto api shown here (documentation also on webpage). I make the correct call but all I get it this error:

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

    Is there a reason for this and a fix? I know it either has to do with openssl or the type of api I'm calling to?

    API: https://www.cryptocompare.com/coins/guides/how-to-use-our-api/

    Current code:
    //pro file
    QT += network
    QT += websockets

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = binance
    TEMPLATE = app

    The following define makes your compiler emit warnings if you use

    any feature of Qt which has been marked as deprecated (the exact warnings

    depend on your compiler). Please consult the documentation of the

    deprecated API in order to know how to port your code away from it.

    DEFINES += QT_DEPRECATED_WARNINGS

    You can also make your code fail to compile if you use deprecated APIs.

    In order to do so, uncomment the following line.

    You can also select to disable deprecated APIs only up to a certain version of Qt.

    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

    CONFIG += c++11

    SOURCES +=
    main.cpp
    widget.cpp

    HEADERS +=
    widget.h

    FORMS +=
    widget.ui

    Default rules for deployment.

    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target


    //widget.h

    #ifndef WIDGET_H
    #define WIDGET_H

    #include <QWidget>
    #include <QtNetwork/QNetworkAccessManager>
    #include <QUrl>
    #include <QUrlQuery>
    #include <QtNetwork/QNetworkReply>
    #include <QJsonArray>
    #include <QJsonDocument>
    #include <QJsonObject>
    #include <QJsonValue>
    #include <QDebug>
    #include <iostream>
    #include <string>
    #include <stdio.h>
    #include <QtWebSockets/QtWebSockets>
    #include <QSslSocket>

    using namespace std;

    namespace Ui {
    class Widget;
    }

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    string apiKey = "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A";
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

    private:
    Ui::Widget *ui;

    private slots:
    void managerFinished(QNetworkReply *reply);
    };

    #endif // WIDGET_H


    //widget.cpp

    #include "widget.h"
    #include "ui_widget.h"

    using namespace std;

    Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {

    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    QUrl myUrl("https://min-api.cryptocompare.com/data/pricemulti?fsyms=ETH,DASH&tsyms=BTC,USD,EUR&api_key=3f8d2ada68e40eab3e20ea047d34530b28922f7ced692603334ddff18455f90b");
    QNetworkRequest myRequest(myUrl);
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(managerFinished(QNetworkReply*)));
    manager->get(myRequest);
    ui->setupUi(this);
    

    }

    Widget::~Widget()
    {
    delete ui;
    }

    void Widget::managerFinished(QNetworkReply *reply) {
    QByteArray *myByteArray = new QByteArray();
    myByteArray->append(reply->readAll());
    string str = myByteArray->toStdString();
    qDebug() <<"str" << str.c_str();
    QJsonDocument myJson = QJsonDocument::fromJson(*myByteArray);
    //Now use QJsonObject and QJsonArray to parse the Json
    }

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

      Hi,

      What version of Qt are you using ?
      What platform are you running on ?

      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
      • C Offline
        C Offline
        ckzaner
        wrote on last edited by
        #3

        I am running Qt Cteator 4.8.0 Community on Windows 10.

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

          Again: what version of Qt are you using ?
          Do you have OpenSSL installed on your system ?

          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
          • C Offline
            C Offline
            ckzaner
            wrote on last edited by
            #5

            Apologies I thought 4.8 was the version, that's just what it shows when I open it. I installed 5.12.0.

            I recently downloaded openssl-1.0,2a-win32-mingw so I have OpenSSL downloaded.

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

              No, that's the Qt Creator version which is unrelated to the Qt version you are using to build your application.

              IIRC, Qt 5,12 is using OpenSSL 1.1. The OpenSSL 1.1 series is not backward compatible with the OpenSSL 1.0 series.

              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
              1
              • C Offline
                C Offline
                ckzaner
                wrote on last edited by
                #7

                Ok so Qt 5.12.
                Currently I have no OpenSSL from before 1.1 attached to the project though. I have 1.0.2 in my downloads but it currently is not associated with Qt or the project. Knowing this and seeing the code, any idea how to fix the error?

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

                  Download OpenSSL 1.1 and then in the Run part of the Project panel, modify the PATH environnement variable and add the folder where the OpenSSL .dll files can be found.

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

                  C 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Download OpenSSL 1.1 and then in the Run part of the Project panel, modify the PATH environnement variable and add the folder where the OpenSSL .dll files can be found.

                    C Offline
                    C Offline
                    ckzaner
                    wrote on last edited by
                    #9

                    @SGaist My I ask how to actually do that? I have the file in C:/OpenSSL-Win64 but I'm not sure where to exactly add it or insert it? I don't see an explicit PATH environment variable that this could be added to, or at least if I do see it I'm unsure if it is it.

                    jsulmJ 1 Reply Last reply
                    0
                    • C ckzaner

                      @SGaist My I ask how to actually do that? I have the file in C:/OpenSSL-Win64 but I'm not sure where to exactly add it or insert it? I don't see an explicit PATH environment variable that this could be added to, or at least if I do see it I'm unsure if it is it.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @ckzaner Did you check the Run settings as @SGaist suggested?
                      I'm pretty sure you have PATH variable under "Run Environment" there.
                      So, click on "Projects" at the left side in QtCreator and select "Run" in the Kit you're using and then expand "Run Environment".
                      You need to add the path containing OpenSSL libraries to PATH there.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      C 1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        ckzaner
                        wrote on last edited by ckzaner
                        #11

                        Ok so I went from Projects--->Run (on left side underneath Build)
                        There is not anything explicitly called the PATH environment or anything like that.
                        There is the section under Run which shows me the Run Configuration which shows my current directory for the project.
                        Would I select "add" here and then give the directions to the OpenSSL-Win64 file?

                        Edit::: @jsulm Actually at the bottom there is a Run Environment section. I'll see if I do this right.
                        I'm assuming select add, name it opensslv1.1, then give path to the libs folder and that's it?

                        1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @ckzaner Did you check the Run settings as @SGaist suggested?
                          I'm pretty sure you have PATH variable under "Run Environment" there.
                          So, click on "Projects" at the left side in QtCreator and select "Run" in the Kit you're using and then expand "Run Environment".
                          You need to add the path containing OpenSSL libraries to PATH there.

                          C Offline
                          C Offline
                          ckzaner
                          wrote on last edited by ckzaner
                          #12

                          @jsulm So I have this in the Run Environment now.
                          0_1545118944140_openssl.PNG
                          I assume there's more to be done?
                          I still get the same error "qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed"

                          jsulmJ 1 Reply Last reply
                          0
                          • C ckzaner

                            @jsulm So I have this in the Run Environment now.
                            0_1545118944140_openssl.PNG
                            I assume there's more to be done?
                            I still get the same error "qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed"

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @ckzaner You need to change PATH variable there as @SGaist suggested...

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            C 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @ckzaner You need to change PATH variable there as @SGaist suggested...

                              C Offline
                              C Offline
                              ckzaner
                              wrote on last edited by
                              #14

                              @jsulm I found "Path". Maybe I need to change something else?
                              This is the value now:
                              C:\Qt\Tools\mingw730_64\bin;C:\Qt\5.12.0\mingw73_64\bin;C:\Qt\Tools\mingw730_64\bin;C:\OpenSSL-Win64\bin;C:\Windows\system32;......(so on so forth).

                              The bin has all the .dll folders. Not sure if Qt is using them though. I used the line:
                              qDebug() <<"ssl:" << QSslSocket::sslLibraryBuildVersionString();
                              to try and see if Qt was using it but it says OpenSSL 1.0.2p

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

                                Ok, then in that case, point it to the OpenSSL 1.0 you installed on your machine.

                                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
                                1
                                • Y Offline
                                  Y Offline
                                  Yash001
                                  wrote on last edited by Yash001
                                  #16
                                  This post is deleted!
                                  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