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. Why the post method doesn't send the json to API Rest in QT5?
Forum Updated to NodeBB v4.3 + New Features

Why the post method doesn't send the json to API Rest in QT5?

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 4 Posters 7.3k Views 1 Watching
  • 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.
  • T trip
    20 Oct 2016, 14:53

    @raven-worx
    I tried to do another project where there is just main.cpp and where do

    #include <QCoreApplication>
    #include <QNetworkAccessManager>
    #include <QNetworkReply>
    #include <QNetworkRequest>
    #include <QDebug>
    #include <QObject>
    #include <QByteArray>
    #include <QUrl>
    
    
    void replyFinished(QNetworkReply *reply)
    {
        reply->deleteLater();
        qDebug() << "reply delete!";
        qDebug() << "https post_request done!";
    }
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        QNetworkAccessManager *manager = new QNetworkAccessManager();
    
        QNetworkRequest request(QUrl ("https://cryptic-reaches-94837.herokuapp.com/data/"));
    
        request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    
        QObject::connect(manager, &QNetworkAccessManager::finished, replyFinished);
    
        quint8 speed = 0x12;
        quint8 acceleration = 0x5b;
    
        QString json = QString("{\"speed\":\"%1\",\"acceleration\":\"%2\"}").arg(speed).arg(acceleration);
    
        manager->post(request, json.toUtf8());
    
        return a.exec();
    }
    

    and it's work!!!
    but how come if add this piece of code to my project, why does not work to me?

    R Offline
    R Offline
    raven-worx
    Moderators
    wrote on 20 Oct 2016, 15:40 last edited by
    #21

    @trip
    but thats a different URL now?!
    Check the returned response error again.

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    1 Reply Last reply
    0
    • T Offline
      T Offline
      trip
      wrote on 21 Oct 2016, 07:27 last edited by
      #22

      @raven-worx
      not only here I left explicit

      1 Reply Last reply
      0
      • T Offline
        T Offline
        trip
        wrote on 21 Oct 2016, 14:11 last edited by
        #23

        @raven-worx
        I think the problem of my code is that networking events are not processed by QCoreApplication :: exec () and then, because the execution is always nested in the cycles and never returns to the main unless there is an error , I do not run networking events. How can I solve this problem?

        1 Reply Last reply
        0

        21/23

        20 Oct 2016, 15:40

        • Login

        • Login or register to search.
        21 out of 23
        • First post
          21/23
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved