Results 1 to 3 of 3

Thread: web server connection

  1. #1
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default web server connection

    Hi everyone,
    I am trying to connect to web server.For that i have 3 function(A,B,X).

    code of A :-(for sending request)
    Qt Code:
    1. mang= new QNetworkAccessManager();
    2. connect(mang, SIGNAL(finished(QNetworkReply*)),this,SLOT(B(QNetworkReply* )));
    3. QNetworkRequest request(QUrl("http://192.168.1.95/test/default.aspx"));
    4. mang->post(request,data);
    To copy to clipboard, switch view to plain text mode 

    code of B ;- (reply of server)
    Qt Code:
    1. B( QNetworkReply* reply)
    2. {
    3. data=reply->readAll();
    4. }
    To copy to clipboard, switch view to plain text mode 


    X is the function where i am trying to call A.

    But problem is the data which i received from server is required inside X (means i want to use that data inside X). But i received the data after X function.

    Is there any way so that i can use the data in side X.

    thanks.

  2. #2
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: web server connection

    You can use blocked mode (from QIODevice::waitForReadyRead), but best way of code is use two function Y and Z. Where Y is first part of X. And Z is second (Also you can use signals|and slot). Example of code that i'm use:

    A (called from Y):

    Qt Code:
    1. reply = manager.get(QNetworkRequest(apiUrl));
    2. connect(reply, SIGNAL(finished()),this, SLOT(on_replyfinish()));
    3. connect(reply, SIGNAL(readyRead()), this, SLOT(on_read()));
    4. connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors()));
    To copy to clipboard, switch view to plain text mode 

    on_read():
    Qt Code:
    1. void MainWindow::on_read()
    2. {
    3. result+=reply->readAll();
    4. }
    To copy to clipboard, switch view to plain text mode 

    on_replyfinish():

    Qt Code:
    1. void MainWindow::on_replyfinish()
    2. {//oh, called on error or when all data is readed.
    3. if(reply->error()!=QNetworkReply::NoError)
    4. {
    5. //error handle
    6. }
    7. else
    8. {
    9. Z();
    10. }
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to unit for this useful post:

    sattu (3rd March 2011)

  4. #3
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: web server connection

    thanks for reply.Now it is working.

Similar Threads

  1. [TCP Server] Server only sending when terminating
    By papperlapapp in forum Qt Programming
    Replies: 0
    Last Post: 6th December 2010, 20:41
  2. VPN connection
    By baobui in forum Newbie
    Replies: 6
    Last Post: 20th October 2010, 23:56
  3. Replies: 1
    Last Post: 2nd April 2010, 07:42
  4. Replies: 5
    Last Post: 2nd June 2009, 20:47
  5. connection
    By mickey in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2006, 21:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.