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

How to connect via API?

Scheduled Pinned Locked Moved Solved General and Desktop
66 Posts 8 Posters 13.5k 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
    #61

    I tested your query on macOS and it worked fine. What exact version of Windows 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
    1
    • M Offline
      M Offline
      Mikeeeeee
      wrote on last edited by
      #62

      Yes, I use Windows

      jsulmJ 1 Reply Last reply
      0
      • M Mikeeeeee

        Yes, I use Windows

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

        @Mikeeeeee Do you think "Yes, I use Windows" is a useful answer to "What exact version of Windows are you using?"?!
        We already know that you're using Windows, the question was which exact version?...
        Why can't you give exact answers and ask questions which can actually be understood?

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

        1 Reply Last reply
        1
        • M Offline
          M Offline
          Mikeeeeee
          wrote on last edited by Mikeeeeee
          #64

          Sorry, I use Windows 7 pro 64bit.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mikeeeeee
            wrote on last edited by
            #65

            The problem turned out to be a large file size. You should read line by line.

            Заголовочный файл
            #ifndef MAINWINDOW_H
            #define MAINWINDOW_H
             
            #include <QMainWindow>
            #include "QDebug"
            #include "QtNetwork/QNetworkAccessManager"
            #include "QtNetwork/QNetworkRequest"
            #include "QtNetwork/QNetworkReply"
            #include <QUrl>
            #include <QJsonArray>
            #include <QJsonDocument>
            #include <QJsonObject>
            #include <QJsonValue>
            #include <QTextCodec>  // для преобразования кодировки
            //#include "e_os.h"
             
            namespace Ui {
            class MainWindow;
            }
             
            class MainWindow : public QMainWindow
            {
                Q_OBJECT
             
            public:
                explicit MainWindow(QWidget *parent = nullptr);
                ~MainWindow();
             
            private slots:
                void on_testButton_clicked();
                void onReply(QNetworkReply* reply);
             
            private:
                Ui::MainWindow *ui;
                QNetworkAccessManager m_apiQuery;
            };
             
            #endif // MAINWINDOW_H
             
            Файл реализации
            #include "mainwindow.h"
            #include "ui_mainwindow.h"
             
            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
                connect(&m_apiQuery, &QNetworkAccessManager::finished, this, &MainWindow::onReply);
            }
             
            MainWindow::~MainWindow()
            {
                delete ui;
            }
             
            void MainWindow::on_testButton_clicked()
            {
                QNetworkRequest request;
                request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=compact&apikey=63YUZ8NP5SW1D302"));
                m_apiQuery.get(request);
            }
             
             
            void MainWindow::onReply(QNetworkReply* reply){
                QByteArray replyArray;
                while (!reply->atEnd()) {
                    replyArray.append(reply->readLine());
                }
                QJsonDocument doc = QJsonDocument::fromJson(replyArray);
                qDebug() << doc;
                reply->deleteLater();
            }
            
            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #66

              How large is 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
              0

              • Login

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