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
    Kranj, Slovenia
    Posts
    34
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5

    Default Re: QHttp related

    thanks for noticing that. it was my mistake, when i rewrite the code to make it clearer and to show just where my problem is i forgot to insert a lass to skoci() function...
    Qt Code:
    1. if (error) {
    2. //insert the error string into textfield t_2
    3. //just to find out what the error is
    4. ui.t_2->insertPlainText("\n" + ui.t_1->text() + ": " + http->errorString());
    5. skoci();
    6. }
    7. else {
    8. bool bOk;
    9. QString str = ui.t_1->text();
    10. int st = str.toInt(&bOk) + 1;
    11. if (st <= 10) {
    12. skoci();
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    As far as I understand QHttp mechanism (am a beginner at it) when a get() is finished a requestFinished() signal is send. I have connected requestFinished() with httpRequestFinished() and responseHeaderReceived() with readResponseHeader()... Therefor when get() finish the httpRequestFinished() is called. At that point I call again the function skoci() and repeat this 10 times. It works with second and third URL (responseHeaderRecieved codes 404 and 200, but with the first one I do not get a responseHeaderReceived() since the host does not exist. In return I get an error, but when I try to call skoci() function from that error I call it but the get() is not called again...
    Timer::SingleShot() does not work in this contect - the second time the function skoci() is not called!
    There is obiously something wrong with my aproach to this problem, but I can not find where I made a mistake...

    Regards, Luka

  2. #2
    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
    It works with second and third URL (responseHeaderRecieved codes 404 and 200, but with the first one I do not get a responseHeaderReceived() since the host does not exist. In return I get an error, but when I try to call skoci() function from that error I call it but the get() is not called again...
    Do you change the host after the error has occured?

    Add this at the beginning of httpRequestFinished():
    Qt Code:
    1. qDebug() << httpGetId << requestId << error;
    To copy to clipboard, switch view to plain text mode 
    and this at the end of skoci():
    Qt Code:
    1. qDebug() << urlt.host() << httpGetId;
    To copy to clipboard, switch view to plain text mode 
    to see what's happening (don't forget about #include <QtDebug>).

    Quote Originally Posted by whoops.slo
    Timer::SingleShot() does not work in this contect - the second time the function skoci() is not called!
    Is that skoci() method a slot? Anyway you can forget about QTimer as QHttp is reentrant, so you can safely invoke setHost() and get() whenever you want.

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

    Default Re: QHttp related

    skoci() is not a slot - at least it was not meant to be...

    I try what you suggest - qDebbug(). I am using Win XP, CodeBlock, MinGW and GDB and am new with debbugers. Therefor I can not understand what I should read from it (perhaps I have some setting set incorrectly). If you or somebody else have time and will to teach me how to set debbuger in this enviroment I would be most greatefull, since than I could at least look into what my app. is actually working

    Thanks anyway for your help, I hope you can help me further, but if it is a lost case than... I will understand

    Regards,
    Luka

  4. #4
    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
    skoci() is not a slot - at least it was not meant to be...
    That explains why the trick with QTimer didn't work.

    Quote Originally Posted by whoops.slo
    I am using Win XP, CodeBlock, MinGW and GDB and am new with debbugers. Therefor I can not understand what I should read from it
    Under windows you must add "CONFIG += console" to your .pro file to see the qDebug() output. Although debugger should be able to intercept these messages without it. Unfortunately I don't do much development under windows, so I can't help you with it.

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

    Default Re: QHttp related

    I was not able to get anything from the debugger. Instead I put requested strigns to be send to the textbox. This is the response I got from using host, that do not exist:
    2
    2, 1
    2, 2
    1: Host www.anabanana.brb not found
    5
    And this is from the one that exist (The "loop" run 5 times):
    2
    2, 1
    1: 200
    2, 2
    4
    4, 3
    2: 200
    4, 4
    6
    6, 5
    3: 200
    6, 6
    8
    8, 7
    4: 200
    8, 8
    10
    10, 9
    5: 200
    10, 10
    I put the line below at the end of the skoci():
    Qt Code:
    1. ui.t_2->insertPlainText("\n" + QString::number(httpGetId));
    To copy to clipboard, switch view to plain text mode 
    and the line below at the beggining of httpRequestFinished():
    Qt Code:
    1. ui.t_2->insertPlainText("\n" + QString::number(httpGetId) + ", " + QString::number(requestId));
    To copy to clipboard, switch view to plain text mode 
    Can this help?
    Regards, Luka

  6. #6
    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

    What happens when you change skoci() like this?
    Qt Code:
    1. http->setHost( "localhost" ); // added
    2. http->setHost( urlt.host() );
    3. httpGetId = http->get( urlt.path(), file );
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QHttp related

    I get the same responce:
    3
    3, 1
    3, 2
    3, 3
    6
    I'll try something else... Before I call GET() I will check for ERROR(). If ERROR() is HostNotFound than GET() will not be called...
    Last edited by whoops.slo; 20th June 2006 at 07:08.

  8. #8
    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.

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

    whoops.slo (20th June 2006)

  10. #9
    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.