can't get JSON file from QNetworkReply
Solved
General and Desktop
-
hello, i don't know what is happening to my Qt
i have to get a JSON file from a request to Google Maps API Geocoding, when i send a request using QNetworkAccessManager, it shown in the consol reply->size() == 0 so there is no file returned
but when i load it in a web Page with QWebEngineView pageWeb->load(QUrl(url2)); i can se the JSON filei don't know why it not work by a request and it work in a web page
this is the code :
QUrl url2 ("https://maps.googleapis.com/maps/api/geocode/json?address="+adresse + ",+Algérie&key="+MY_API_KEY); QNetworkRequest request; request.setUrl(url2); m_pNetworkAccessManager->get(request); connect(m_pNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); pageWeb->load(QUrl(url2)); pageWeb->show(); void MainWindow::replyFinished(QNetworkReply *reply) { std::cerr << (reply->size()) << endl; QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); QJsonObject rootObj = document.object(); if(rootObj.empty()) ui->statusBar->showMessage("vide"); else ui->statusBar->showMessage("ayah machi vide !!!"); }