Here is my code. It retrieves the wanted information from the database, but it doesnt go into the foreach loop so I cant include the response data into the saldo attribute.
void engine::makeSaldoRequest(){
QString site_url="http://localhost:3000/tili/1";
QString credentials="automaatti1:raha123";
QNetworkRequest request((site_url));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QByteArray data = credentials.toLocal8Bit().toBase64();
QString headerData = "Basic " + data;
request.setRawHeader( "Authorization", headerData.toLocal8Bit());
qDebug() << "haetaan saldo";
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished (QNetworkReply*)),
this, SLOT(saldoReplySlot(QNetworkReply*)));
saldoReply = manager->get(request);
}
void engine::saldoReplySlot(QNetworkReply *saldoreply){
QByteArray response_data=saldoreply->readAll();
qDebug() << response_data;
QJsonDocument json_doc=QJsonDocument::fromJson(response_data);
QJsonArray json_array=json_doc.array();
QString saldo;
foreach(const QJsonValue &value, json_array){
QJsonObject json_object=value.toObject();
saldo+=QString::number((json_object["idtili"].toInt()))+" "+
json_object["tilin_saldo"].toString()+"\r\n";
qDebug() << "loopissa";
}
qDebug() << "lähetetään signaali exelle missä saldo on";
emit saldoToExe(saldo);
qDebug() << saldo;
manager->deleteLater();
saldoReply->deleteLater();
saldoreply->deleteLater();
}