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. can't get JSON file from QNetworkReply
Forum Updated to NodeBB v4.3 + New Features

can't get JSON file from QNetworkReply

Scheduled Pinned Locked Moved Solved General and Desktop
qnetreplyqnetworkrequestqwebengineviewqnetworkaccessmjson
2 Posts 1 Posters 5.5k Views
  • 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.
  • nazimGTN Offline
    nazimGTN Offline
    nazimGT
    wrote on last edited by
    #1

    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 file

    i 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 !!!");
    }
    
    1 Reply Last reply
    0
    • nazimGTN Offline
      nazimGTN Offline
      nazimGT
      wrote on last edited by
      #2

      resolved !!
      i've chenged

      m_pNetworkAccessManager->get(request);
      

      by

      request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
      QByteArray par="";
      m_pNetworkAccessManager->post(request,par);
      
      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