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. windows app for simle API get : TLS initialization failed
Forum Updated to NodeBB v4.3 + New Features

windows app for simle API get : TLS initialization failed

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 3 Posters 1.1k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #6

    Why ? Because Qt does not provide OpenSSL due to some international restriction. You have to provide OpenSSL yourself if your application need some it.

    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
    2
    • L Offline
      L Offline
      louis cordhomme
      wrote on last edited by
      #7

      haa ok,
      but how do we provide OpenSSL then?
      Sorry about my lack of knowledge of the subject
      Thank you very much.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        louis cordhomme
        wrote on last edited by
        #8

        It's okay, I actually made it.

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

          Everything is working ?

          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
          • L Offline
            L Offline
            louis cordhomme
            wrote on last edited by louis cordhomme
            #10

            almost,
            I'm getting to have my xml thong
            but my "onmanagerfinished" method only runs after my on _button_clicked method.

            my constructor :

            MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                , ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            
                manager = new QNetworkAccessManager();                      
                QObject::connect(manager,&QNetworkAccessManager::finished,  
                                 this, [=](QNetworkReply *reply) {          
                    if (reply->error()) {
                        qDebug() << reply->errorString();
                        return;
                    }
                    answer = reply->readAll();
                    qDebug() << answer;
                });
            

            but it's return this (qDebug())

            #########################################OKbegin
            
            #########################################GetuuidBegin
            
            #########################################GetuuidEnd 
            Answer ---->  ""
            
            #########################################OKend 
            UUID -------> ""
            "{\"id\":\"069a79f444e94726a5befca90e38aaf5\",\"name\":\"Notch\"}"
            

            my methodes :

            QString MainWindow::GetUUID(QString Pseudo)
            {
                qDebug()<<"\n#########################################GetuuidBegin";
            
                QString str = "https://api.mojang.com/users/profiles/minecraft/" + Pseudo + "?at=" + getTimeStamp();   
                request.setUrl(QUrl(str));                                                                             
                manager->get(request);                                                                                 
            
                qDebug()<<"\n#########################################GetuuidEnd"
                        <<"\nAnswer ----> "<< answer;
            
                return  answer;
            }
            
            void MainWindow::on_OK_clicked()
            {
                qDebug() <<"\n#########################################OKbegin";
                QString UUID = GetUUID(ui->Speudo->text());
            
                qDebug() <<"\n#########################################OKend"
                         << "\nUUID ------->"<< UUID;
            
            
            

            PS : what I call onManagerFinished is:

            [=](QNetworkReply *reply) {          
                    if (reply->error()) {
                        qDebug() << reply->errorString();
                        return;
                    }
                    answer = reply->readAll();
                    qDebug() << answer;
                }
            

            because I used to use an onManagerFinished method instead

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

              Your slot (well lambda in this case) will be called asynchronously at some point when the answer to the request is completely received. What you are doing now is calling your qDebug statement right after you made your request which is not yet done or might not even have been sent to the server yet.

              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
              • L Offline
                L Offline
                louis cordhomme
                wrote on last edited by
                #12

                yes I understand I only receive the answer when it is completely received, so I need to use reply.isFinished(), but where ? I'm not sure I understand how to use it (even with the doc)

                mrjjM 1 Reply Last reply
                0
                • L louis cordhomme

                  yes I understand I only receive the answer when it is completely received, so I need to use reply.isFinished(), but where ? I'm not sure I understand how to use it (even with the doc)

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #13

                  @louis-cordhomme said in windows app for simle API get : TLS initialization failed:

                  reply.isFinished()

                  Hi
                  Consider just using signal and slot to solve this asynchronously.
                  (minwindow.h, define a new signal )

                  signal:
                  void AnswerReady(QString Pseudo);

                  then in your

                  QObject::connect(manager,&QNetworkAccessManager::finished,  
                                       this, [=](QNetworkReply *reply) {          
                          if (reply->error()) {
                              qDebug() << reply->errorString();
                              return;
                          }
                          answer = reply->readAll();
                          qDebug() << answer;
                         emit AnswerReady(answer); // tell the world
                      });
                  

                  then connect this new signal to lambda or slot where you do what ever you want to do with the
                  data
                  connect ( this,&Mainwindow::AnswerReady, this, &Mainwindow::ProcessAnswer);

                  void MainWindow::ProcessAnswer(QString answer)
                  {
                      qDebug()<<"\n#########################################GetuuidEnd"
                              <<"\nAnswer ----> "<< answer;  
                  }
                  
                  1 Reply Last reply
                  2
                  • L Offline
                    L Offline
                    louis cordhomme
                    wrote on last edited by
                    #14

                    Actually I'm going to have several different requests to make and I wanted to make methods like getUUID or getXXX
                    I'm not sure I understand how to use ProcessAnswer

                    mrjjM 1 Reply Last reply
                    0
                    • L louis cordhomme

                      Actually I'm going to have several different requests to make and I wanted to make methods like getUUID or getXXX
                      I'm not sure I understand how to use ProcessAnswer

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #15

                      @louis-cordhomme
                      Hi
                      Well the QNetworkAccessManager is by nature asynchronous so you have to code to support that.

                      one way to handle reading different data is to use member variables to keep the state in.

                      void MainWindow::ProcessAnswer(QString answer) {
                      if ( ReadingType == UUID)
                      // use answer for that

                      if ( ReadingType == SOMEOTHER)
                      // use answer for that
                      }

                      Its also possible to connect to signal finished on the QNetworkReply and in that way know which request has which data.

                      I know you wish to do

                      NetworkAccessManager NAManager;
                      QUrl url ("http://www.google.com");
                      QNetworkRequest request(url);
                      QNetworkReply *reply = NAManager.get(request);
                      QEventLoop eventLoop;
                      QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
                      eventLoop.exec(); // it stays in here until its finished.
                      std::cout << "finished" << std::endl; //request finished here
                      

                      where is synchronous in nature and feels easier to code but its kinda bad design and should be avoided.

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

                        Is there a set of steps to follow one after the other ?
                        If so, you may want to consider using a state machine to model that.

                        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

                        • Login

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