Solved How to connect via API?
-
@Mikeeeeee said in How to connect via API?:
Thanks, corrected. What's next?
That's up to you to figure out.
-
@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);
-
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.
-
@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?
-
@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.
-
@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"; }
-
This should help:
#include <QNetworkReply>
-
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.
-
@Mikeeeeee Internet searching is your friend... maybe this example could help you.
-
This example is not working.
-
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 }
-
Qt says: qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
I have api-key: 63YUZ8NP5SW1D302
How can I use the key? -
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? -
@VRonin said in How to connect via API?:
OpenSSL
This link is nothing about OpenSSL.
OpenSSL need to connect to the project? -
Qt uses OpenSSL to implement TLS and SSL
-
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? -
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.
-
My OS - Windows.
-
-
downloaded openssl-1.1.1b and put it in the folder with the executable file. Did not help.
In openssl-1.1.1b there is no libeay32.dll.