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. How to connect via API?
QtWS25 Last Chance

How to connect via API?

Scheduled Pinned Locked Moved Solved General and Desktop
66 Posts 8 Posters 11.5k Views
  • 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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on 15 May 2019, 08:14 last edited by Mikeeeeee
    #1

    Hi!
    How to connect via API?
    I want to connect to alphavantage.co
    I do this:

    QNetworkAccessManager apiQuery;
        QNetworkRequest request;
        request.setUrl(QUrl("https://  &???"));
    
        apiQuery.get(request);
    

    What and how to finish?

    1 Reply Last reply
    0
    • S Online
      S Online
      sierdzio
      Moderators
      wrote on 15 May 2019, 08:21 last edited by
      #2

      Add QT += network to your .pro file, run qmake and rebuild your project.

      (Z(:^

      1 Reply Last reply
      3
      • M Offline
        M Offline
        Mikeeeeee
        wrote on 15 May 2019, 08:34 last edited by
        #3

        Thanks, corrected. What's next?

        S 1 Reply Last reply 15 May 2019, 08:51
        0
        • M Mikeeeeee
          15 May 2019, 08:34

          Thanks, corrected. What's next?

          S Online
          S Online
          sierdzio
          Moderators
          wrote on 15 May 2019, 08:51 last edited by
          #4

          @Mikeeeeee said in How to connect via API?:

          Thanks, corrected. What's next?

          That's up to you to figure out.

          (Z(:^

          1 Reply Last reply
          2
          • M Offline
            M Offline
            Mikeeeeee
            wrote on 15 May 2019, 08:57 last edited by
            #5

            @sierdzio said in How to connect via API?:

            That's up to you to figure out.

            I would like to get something like this: https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo

            There is only this:

                QNetworkRequest request;
                request.setUrl(QUrl("https://  &???"));
            
                apiQuery.get(request);
            
            1 Reply Last reply
            0
            • S Online
              S Online
              sierdzio
              Moderators
              wrote on 15 May 2019, 09:02 last edited by
              #6

              Well you can just put that URL into setUrl() call, should work.

              Alternatively, you can build the QUrl manually, and add relevant parameters using QUrlQuery.

              (Z(:^

              1 Reply Last reply
              3
              • M Offline
                M Offline
                Mikeeeeee
                wrote on 15 May 2019, 09:29 last edited by
                #7

                @sierdzio said in How to connect via API?:

                Well you can just put that URL into setUrl() call, should work.
                Alternatively, you can build the QUrl manually, and add relevant parameters using QUrlQuery.

                I did this:

                    QNetworkRequest request;
                    request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo"));
                
                    apiQuery.get(request);
                

                How to get and read json now?

                S 1 Reply Last reply 15 May 2019, 10:00
                0
                • M Mikeeeeee
                  15 May 2019, 09:29

                  @sierdzio said in How to connect via API?:

                  Well you can just put that URL into setUrl() call, should work.
                  Alternatively, you can build the QUrl manually, and add relevant parameters using QUrlQuery.

                  I did this:

                      QNetworkRequest request;
                      request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo"));
                  
                      apiQuery.get(request);
                  

                  How to get and read json now?

                  S Online
                  S Online
                  sierdzio
                  Moderators
                  wrote on 15 May 2019, 10:00 last edited by
                  #8

                  @Mikeeeeee said in How to connect via API?:

                  @sierdzio said in How to connect via API?:

                  Well you can just put that URL into setUrl() call, should work.
                  Alternatively, you can build the QUrl manually, and add relevant parameters using QUrlQuery.

                  I did this:

                      QNetworkRequest request;
                      request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo"));
                  
                      apiQuery.get(request);
                  

                  How to get and read json now?

                  See the docs.

                  (Z(:^

                  1 Reply Last reply
                  2
                  • M Offline
                    M Offline
                    Mikeeeeee
                    wrote on 15 May 2019, 11:15 last edited by
                    #9

                    @Mikeeeeee said in How to connect via API?:

                    I did this:

                    I made this code and got an error: invalid application of 'sizeof' to incomplete type 'QNetworkReply'
                    Q_STATIC_ASSERT_X(sizeof(T), "Type argument of Q_DECLARE_METATYPE(T*) must be fully defined");

                    MainWindow::MainWindow(QWidget *parent) :
                        QMainWindow(parent),
                        ui(new Ui::MainWindow)
                    {
                        ui->setupUi(this);
                    
                        connect(apiQuery, &QNetworkAccessManager::finished, this, &MainWindow::testSlotFromQDebug);
                    }
                    
                    MainWindow::~MainWindow()
                    {
                        delete ui;
                    }
                    
                    void MainWindow::on_testButton_clicked()
                    {
                        QNetworkRequest request;
                        request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo"));
                    
                        apiQuery->get(request);
                    }
                    
                    void MainWindow::testSlotFromQDebug()
                    {
                        qDebug()<<"point1";
                    }
                    
                    
                    1 Reply Last reply
                    0
                    • S Online
                      S Online
                      sierdzio
                      Moderators
                      wrote on 15 May 2019, 11:19 last edited by
                      #10

                      This should help:

                      #include <QNetworkReply>
                      

                      (Z(:^

                      1 Reply Last reply
                      4
                      • M Offline
                        M Offline
                        Mikeeeeee
                        wrote on 15 May 2019, 15:08 last edited by
                        #11

                        Thanks, earned. I receive a response signal. But theoretically, a json file should come in response to the request. Please tell me how you can open the response data, read it, and then delete it if it is not deleted by itself.

                        P 1 Reply Last reply 15 May 2019, 17:33
                        0
                        • M Mikeeeeee
                          15 May 2019, 15:08

                          Thanks, earned. I receive a response signal. But theoretically, a json file should come in response to the request. Please tell me how you can open the response data, read it, and then delete it if it is not deleted by itself.

                          P Offline
                          P Offline
                          Pablo J. Rogina
                          wrote on 15 May 2019, 17:33 last edited by
                          #12

                          @Mikeeeeee Internet searching is your friend... maybe this example could help you.

                          Upvote the answer(s) that helped you solve the issue
                          Use "Topic Tools" button to mark your post as Solved
                          Add screenshots via postimage.org
                          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                          1 Reply Last reply
                          3
                          • M Offline
                            M Offline
                            Mikeeeeee
                            wrote on 17 May 2019, 13:36 last edited by
                            #13

                            This example is not working.

                            1 Reply Last reply
                            0
                            • V Offline
                              V Offline
                              VRonin
                              wrote on 17 May 2019, 13:46 last edited by
                              #14

                              delete connect(apiQuery, &QNetworkAccessManager::finished, this, &MainWindow::testSlotFromQDebug);

                              then:

                              void MainWindow::on_testButton_clicked()
                              {
                                  QNetworkRequest request;
                                  request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo"));
                              QNetworkReply* reply = apiQuery->get(request)
                                  connect(reply ,&QNetworkReply::finished,this,std::bind(&MainWindow::on_reply,this,reply ));
                              }
                              void MainWindow::on_reply(QNetworkReply* reply){
                              QJsonDocument jdoc = QJsonDocument::fromJson(reply->readAll());
                              // do something with the jdoc
                              }
                              

                              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                              ~Napoleon Bonaparte

                              On a crusade to banish setIndexWidget() from the holy land of Qt

                              1 Reply Last reply
                              1
                              • M Offline
                                M Offline
                                Mikeeeeee
                                wrote on 17 May 2019, 14:11 last edited by
                                #15

                                Qt says: qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
                                I have api-key: 63YUZ8NP5SW1D302
                                How can I use the key?

                                1 Reply Last reply
                                0
                                • V Offline
                                  V Offline
                                  VRonin
                                  wrote on 17 May 2019, 14:14 last edited by VRonin
                                  #16

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

                                  Make sure you have OpenSSL installed

                                  I have api-key: 63YUZ8NP5SW1D302
                                  How can I use the key?

                                  RTFM: https://www.alphavantage.co/documentation/

                                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                  ~Napoleon Bonaparte

                                  On a crusade to banish setIndexWidget() from the holy land of Qt

                                  1 Reply Last reply
                                  2
                                  • M Offline
                                    M Offline
                                    Mikeeeeee
                                    wrote on 17 May 2019, 14:54 last edited by
                                    #17

                                    @VRonin said in How to connect via API?:

                                    OpenSSL

                                    This link is nothing about OpenSSL.
                                    OpenSSL need to connect to the project?

                                    1 Reply Last reply
                                    0
                                    • V Offline
                                      V Offline
                                      VRonin
                                      wrote on 17 May 2019, 15:48 last edited by
                                      #18

                                      Qt uses OpenSSL to implement TLS and SSL

                                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                      ~Napoleon Bonaparte

                                      On a crusade to banish setIndexWidget() from the holy land of Qt

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        Mikeeeeee
                                        wrote on 17 May 2019, 19:06 last edited by
                                        #19

                                        I installed everything in MaintenanceTool. Do I need to download additional OpenSSL?
                                        If you need to install OpenSSL, then how to connect it to Qt?

                                        SGaistS V 2 Replies Last reply 17 May 2019, 19:31
                                        0
                                        • M Mikeeeeee
                                          17 May 2019, 19:06

                                          I installed everything in MaintenanceTool. Do I need to download additional OpenSSL?
                                          If you need to install OpenSSL, then how to connect it to Qt?

                                          SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 17 May 2019, 19:31 last edited by
                                          #20

                                          Hi,

                                          @Mikeeeeee said in How to connect via API?:

                                          I installed everything in MaintenanceTool. Do I need to download additional OpenSSL?
                                          If you need to install OpenSSL, then how to connect it to Qt?

                                          What OS are you on ? My guess would be Windows.

                                          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

                                          8/66

                                          15 May 2019, 10:00

                                          58 unread
                                          • Login

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