Results 1 to 13 of 13

Thread: QHttp related

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QHttp related

    Quote Originally Posted by whoops.slo
    I get the same responce
    I've made a little experiment:
    Qt Code:
    1. #include <QApplication>
    2. #include <QHttp>
    3.  
    4. class Test : public QObject
    5. {
    6. Q_OBJECT
    7. public:
    8. Test() : QObject( 0 )
    9. {
    10. _http = new QHttp( "www.xxx.zzz", 80, this );
    11. connect( _http, SIGNAL( readyRead( const QHttpResponseHeader & ) ), this, SLOT( read( const QHttpResponseHeader & ) ) );
    12. connect( _http, SIGNAL( requestFinished( int, bool )), this, SLOT( finished( int, bool ) ) );
    13. connect( _http, SIGNAL( done(bool) ), this, SLOT( done(bool) ) );
    14. start();
    15. };
    16.  
    17. private slots:
    18. void start()
    19. {
    20. int id = _http->get( "/" );
    21. qWarning( "start id=%d", id );
    22. }
    23.  
    24. void done( bool error )
    25. {
    26. qWarning("done: %d", error );
    27. qWarning("error: %s", qPrintable( _http->errorString() ) );
    28. // start();
    29. }
    30. void finished( int id, bool error )
    31. {
    32. qWarning("finished: %d %d ", id, error );
    33. start();
    34. }
    35.  
    36. void read( const QHttpResponseHeader& header )
    37. {
    38. qWarning( "code: %d, reason: %s", header.statusCode(), qPrintable( header.reasonPhrase() ) );
    39. qWarning( _http->readAll() );
    40. }
    41.  
    42. private:
    43. QHttp *_http;
    44.  
    45. };
    46.  
    47. int main( int argc, char **argv )
    48. {
    49. QApplication app( argc, argv );
    50. Test t;
    51. return app.exec();
    52. }
    53.  
    54. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    and got this:
    $ ./http
    start id=1
    finished: 1 1
    start id=2
    done: 1
    error: Host www.xxx.zzz not found
    Note that after the second request is started ("start id=2") done() slot is immediately called (with error == true), so it seems that you just start the new request too early.

    There's even and example in the docs:
    For example, if you have the following sequence of requests
    http->setHost("www.foo.bar"); // id == 1
    http->get("/index.html"); // id == 2
    http->post("register.html", data); // id == 3
    and the get() request fails because the host lookup fails, then the post() request is never executed and the signals would look like this:
    requestStarted(1)
    requestFinished(1, false)

    requestStarted(2)
    stateChanged(HostLookup)
    requestFinished(2, true)

    done(true)

    stateChanged(Unconnected)
    But it isn't obvious that this is exactly the same case as in your program.

    If you comment out the call to start() in finished() slot and uncomment the one in done(), QHttp will process requests continuously.

  2. The following user says thank you to jacek for this useful post:

    whoops.slo (20th June 2006)

  3. #2
    Join Date
    Jan 2006
    Location
    Kranj, Slovenia
    Posts
    34
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5

    Default Re: QHttp related

    Thank you for your time! You were correct, the new request was send too early. The example you wrote is just what I needed!

    Thank you again! Regards;
    Luka

Similar Threads

  1. File Binary Upload QHttp find the bug/s
    By patrik08 in forum Qt Programming
    Replies: 13
    Last Post: 10th June 2008, 07:51
  2. QHttp has problems with some url's
    By whoops.slo in forum Qt Programming
    Replies: 2
    Last Post: 2nd June 2006, 23:16
  3. need help for QHttp
    By patcito in forum Qt Programming
    Replies: 9
    Last Post: 1st June 2006, 07:00
  4. using Qhttp with www(x) sites
    By importantman in forum Qt Programming
    Replies: 18
    Last Post: 4th April 2006, 00:12
  5. Help with QHttp needed.
    By bitChanger in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2006, 21:09

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
  •  
Qt is a trademark of The Qt Company.