How to connect via API?
-
Are you sure you put the OpenSSL 1.0 dlls in the right folder ? Without mixing them with another version of OpenSSL.
-
wrote on 25 May 2019, 07:38 last edited by
-
hi
I wonder if it also wants libssl32.dll ? -
wrote on 25 May 2019, 15:30 last edited by
hey @Mikeeeeee,
You can try those .dll. I used it few weeks ago when I needed Qt SSL on Windows and it worked fine.
-
wrote on 26 May 2019, 07:39 last edited by SGaist
Thanks. https is working.
Trying to use the function TIME_SERIES_DAILY_ADJUSTED.
https://www.alphavantage.co/documentation/
If you do so it works:request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=compact&apikey=XXXXXXXXXXXXX"));
If doing so does not work:
request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=full&apikey=XXXXXXXXXXXXXXX"));
It's me doing something wrong or the server is not working?
[edit: removed API key SGaist]
-
Since you don't show how you are processing the QNetworkReply object created for your request one can only guess. What signals did you connect from the reply object ? What exactly do you mean by "does not work" ?
By the way, I've edited out your api key, it's not a good idea to post such information.
-
wrote on 28 May 2019, 08:51 last edited by
It's my h-file:
private slots: void on_testButton_clicked(); void testSlotFromQDebug(); void onReply(QNetworkReply* reply); private: Ui::MainWindow *ui; QNetworkAccessManager *apiQuery = new QNetworkAccessManager;
it's cpp-file:```
#include "mainwindow.h"
#include "ui_mainwindow.h"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_DAILY_ADJUSTED&symbol=MSFT&apikey=demo"));
request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=full&apikey=111111"));
//request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=compact&apikey=1111"));QNetworkReply* reply = apiQuery->get(request); connect(reply ,&QNetworkReply::finished,this,std::bind(&MainWindow::onReply,this,reply ));
}
void MainWindow::testSlotFromQDebug()
{
//qDebug()<<"point1";
}void MainWindow::onReply(QNetworkReply* reply){
QJsonDocument jdoc = QJsonDocument::fromJson(reply->readAll());
//qDebug() << QSslSocket::supportsSsl();
//qDebug() << QSslSocket::sslLibraryBuildVersionString();
//qDebug() << QSslSocket::sslLibraryVersionString();
qDebug()<<jdoc;
// do something with the jdoc
} -
Again: what do you mean by "it's not working" when using the full output size ?
-
wrote on 29 May 2019, 06:15 last edited by Mikeeeeee
Nothing comes back. I do not receive json document.
-
What about connecting the errors related signals ? That might give you some clues about what is happening.
-
wrote on 31 May 2019, 12:17 last edited by
But what signals and slots to use to find the error?
-
wrote on 31 May 2019, 14:05 last edited byThis post is deleted!
-
Maybe QNetworkReply::error ?
-
wrote on 1 Jun 2019, 08:17 last edited by
I get "QNetworkReply::NoError"
-
Did you also check QNetworkReply::sslErrors ?
-
wrote on 3 Jun 2019, 11:15 last edited by
But it's a signal. And what should be placed instead of const QList<QSslError> &errors?
-
Lifetime Qt Championwrote on 3 Jun 2019, 11:33 last edited by jsulm 6 Mar 2019, 11:35
@Mikeeeeee said in How to connect via API?:
But it's a signal
Yes, and you can connect a slot to a signal...
"And what should be placed instead of const QList<QSslError> &errors?" - ?
Nothing, you implement a slot with same parameter and connect it to the signal as usual:void MyClass::handleSslErrors(const QList<QSslError> &errors) { ... }
-
wrote on 3 Jun 2019, 18:07 last edited by Mikeeeeee 6 Mar 2019, 18:13
Did so, the slot does not work. So no mistakes.
connect(reply, & QNetworkReply::sslErrors , this, &MainWindow::testSlotFromQDebug);
-
wrote on 3 Jun 2019, 18:19 last edited by
The server seems to works too, because when you click on the link https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=full&apikey=demo open the file. Maybe this is due to the fact that the file is large?
-
I tested your query on macOS and it worked fine. What exact version of Windows are you using ?
51/66