Results 1 to 3 of 3

Thread: problem with Synchronous Http request

  1. #1
    Join Date
    Dec 2008
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Post problem with Synchronous Http request

    HI,

    I am using Qt-extended4.43.
    i am trying to make synchronous http connection.but its not connecting.

    Can any one help me?
    Here is the sample code.

    Qt Code:
    1. bool syncPostURL( const QUrl& url, const QByteArray& data) {
    2. ///connect the requestFinished signal to our finished slot
    3. connect(this,SIGNAL(requestFinished(int,bool)),SLOT(finished (int,bool)));
    4. QHttpRequestHeader header("POST", url.path());
    5. header.setContentType("application/x-www-form-urlencoded");
    6. header.setValue("Host", url.host());
    7.  
    8. /// start the request and store the requestID
    9. requestID = request(header,data);
    10.  
    11. /// block until the request is finished
    12. loop.exec();
    13. /// return the request status
    14. return status;
    15. }
    16.  
    17. virtual void finished ( int idx, bool err )
    18. {
    19. /// check to see if it's the request we made
    20. if ( idx!=requestID )
    21. return;
    22. /// set status of the request
    23. status = !err;
    24. /// end the loop
    25. loop.exit();
    26. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 29th January 2009 at 14:27. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with Synchronous Http request

    The loop will exit on the first request being finished and the first request is a call to setHost(). Connect to done() instead.

  3. #3
    Join Date
    Dec 2008
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Re: problem with Synchronous Http request

    Thanx for the reply.............Now, My next question is

    Above code is working in QtEmbedded as well as Qt -X11.
    But it is not connecting in QT Extended.

    The only difference is in writing the main() function.

    In Qt Extended the main() function is

    QTOPIA_ADD_APPLICATION(QTOPIA_TARGET, MYCLASS)
    QTOPIA_MAIN

    In Qt X11 and Qt-Embeded the main function is

    int main(int argc , char * argv[])
    { QApplication app (argc, argv);
    MYCLASS obj;
    return app.exec()
    }

Similar Threads

  1. How do I send data with http post request?
    By Morea in forum Qt Programming
    Replies: 13
    Last Post: 21st January 2009, 22:51
  2. QHttp request problem on MAC Pro
    By gamitkumar in forum Qt Programming
    Replies: 1
    Last Post: 30th December 2008, 12:47
  3. http request
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 28th December 2008, 19:19
  4. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  5. Synchronous Http (Good reason)
    By umbrella in forum Qt Programming
    Replies: 5
    Last Post: 4th April 2008, 14:14

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.