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. [Split] Using HTTP for data transfer
Qt 6.11 is out! See what's new in the release blog

[Split] Using HTTP for data transfer

Scheduled Pinned Locked Moved General and Desktop
23 Posts 5 Posters 25.8k 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.
  • P Offline
    P Offline
    pranj51
    wrote on last edited by
    #21

    Thanks for the tips I'll take care that I follow them from next time onwards...
    During this one day I was able to post my data on my server successfully..to give you a precise idea about server side,it is a simple servlet code & all that it does is checks whether there are two Parameters in the URL, and if yes then t records/writes those parameters in a text file on server.
    Till this part everything is running fine..
    But now I want to retrieve data from sever. for e.g If I have passed my user name and password as parameters can i just send the client same parameters back as a concatenated string? And then display it on my GUI? I have written the code that will send the data back to client in my servlet file,so according to me the problem is in my qt code.
    As http is asynchronous protocol I'm bit unclear about how to achieve it...can you guide me through this ?
    I hope I have provided sufficient information this time….If you want to have a look at my qt code I am copying it down for you..

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pranj51
      wrote on last edited by
      #22

      @
      #include "mynetclass.h"#include "ui_mynetclass.h" mynetclass::mynetclass(QWidget *parent) :QMainWindow(parent),ui(new Ui::mynetclass){ui->setupUi(this);connect_server();} mynetclass::~mynetclass(){delete ui;} void mynetclass::connect_server(){QNetworkAccessManager manager = new QNetworkAccessManager(); QString strurl= "http://anush/alva/SlCustomObject_AndroidCalls?Param_one=51&Param_two =51";QUrl url( strurl, QUrl::TolerantMode ); QNetworkRequest request;request.setUrl(url);QNetworkReply reply=manager->get(request); QByteArray bytes = reply->readAll(); QString str(bytes); // string ui->resp->setText(str);}#include "mynetclass.h"
      #include "ui_mynetclass.h"

      mynetclass::mynetclass(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::mynetclass)
      {
      ui->setupUi(this);
      connect_server();
      }

      mynetclass::~mynetclass()
      {
      delete ui;
      }

      void mynetclass::connect_server()
      {
      QNetworkAccessManager manager = new QNetworkAccessManager();
      QString strurl= "http://anush/alva/SlCustomObject_AndroidCalls?Param_one=pranj&Param_two =abcd";
      QUrl url( strurl, QUrl::TolerantMode );
      QNetworkRequest request;
      request.setUrl(url);
      //fetching reply from server
      QNetworkReply
      reply=manager->get(request);
      QByteArray bytes = reply->readAll();
      QString str(bytes); // string
      ui->resp->setText(str);//displaying response to the user
      }@

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #23

        The QNetworkAccessManager classes are asynchronous. That means, the call to manager->get() returns immediately. You will have to connect to the finished signal and only handle the result at this point.

        For the data itself, it is up to you how you format that. I personally would prefer some XML for that, but something different can be ok too. A simple line separated format comes into mind. E.g. with a status code in the first line (OK, ERROR, maybe WARNING) and the payload (in case of OK, maybe split in multiple lines) or a verbose error message (in case of ERROR) afterwards.

        http://www.catb.org/~esr/faqs/smart-questions.html

        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