Results 1 to 11 of 11

Thread: QHttp never end

  1. #1
    Join Date
    Oct 2008
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QHttp never end

    Hi,

    I tried to performe a simple request with QHtpp object. Everything works well and my code pass correctly by the both slots: "done" and "requestFinished".
    But when the QUrl adress is not valid or correct, QHttp doesn't pass througth any slot. So, How I can know if the request failed ? It's like the request never endding !
    Can you help me to solve this problem, thank.

    Qt Code:
    1. QHtpp *http;
    2. QFile *page_html;
    3. ...
    4. ..
    5. QUrl adresse("http://forum.qtfr.org");
    6. page_html = new QFile(windowTitle()+"_page.html");
    7. page_html->setPermissions(QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther) ;
    8. http = new QHttp(adresse.host(),80);
    9. if (http!=NULL) {
    10. connect(http, SIGNAL(done(bool)), this, SLOT(http_done(bool)));
    11. connect(http, SIGNAL(requestFinished(int ,bool )), this, SLOT(http_requestFinished(int, bool)));
    12. http->get(adresse.toString(),page_html);
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp never end

    You can try:
    QUrl::isValid ().

    And you should better connect dataReadProgress signal of QHttp. to see the progress..
    Try also connecting requestStarted signal.

  3. #3
    Join Date
    Oct 2008
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp never end

    Thank, but this command doesn't solve my problem. It just test if Url is valid no if the Url exists or not. It not able to indicate for example if the host is off. In these cases my problem is the same.

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy Re: QHttp never end

    Then you have to set some time out value for http command.
    I dont know how to do that with QHttp. But QTCPSocket is great way to do that.
    And you can do all things with QTcpSocket, whatever you can do with QHttp. Because ultimately the socket is in charge of everything.

    Example:
    Qt Code:
    1. sock.connectToHost(host,80);
    2. if(!sock.waitForConnected()) // HERE YOU CAN SET THE TIME OUT VALUE
    3. {
    4. errorString = sock.errorString();
    5. return false;
    6. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Oct 2008
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp never end

    Ok, but if I replace Host by my adress (for example "http://forum.qtfr.org") that doesn't work !
    And finally, It's a ways to bypass the problem. I would find the reason frozen my QHttp object. It's not a normal behaviour

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp never end

    Quote Originally Posted by didcea View Post
    Ok, but if I replace Host by my adress (for example "http://forum.qtfr.org") that doesn't work !
    What happens, it connects or not?
    See if you can ping this host with your machine's command prompt successfully, then you can connect it via QTcpSocket too.

    And finally, It's a ways to bypass the problem.
    No, this is fastest way to check that, any URL is working or not.
    This code also checks, that your machine is properly connected to internet or not. May be you require the proxy settings, if you are connected via, proxy server.

    I would find the reason frozen my QHttp object. It's not a normal behaviour
    Qt, says QHttp works Asynchronously, means never blocks. So ideally it should not block anywhere. But its great if you find out the reason in your case.

  7. #7
    Join Date
    Oct 2008
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp never end

    Socket connection did not works when QHttp request works correctly !

    Your're rigth, QThhp is asynchone, but I don't anderstand wiht the done slop(bool error) is not call with error flag set to 1, when the connection failed.

  8. #8
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp never end

    Quote Originally Posted by didcea View Post
    Socket connection did not works when QHttp request works correctly !
    Can you explain this?

    Quote Originally Posted by didcea View Post
    Your're rigth, QThhp is asynchone, but I don't anderstand wiht the done slop(bool error) is not call with error flag set to 1, when the connection failed.
    You can find out the problem area by checking the state using
    signal stateChanged.
    This signal emits with current state. And I am sure, you will get enough information about pin pointing the probblematic area.

  9. #9
    Join Date
    Oct 2008
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp never end

    I mean, I test valid Url with QHttp which works fine, but this same Url ddin't work with socket.

    I test stateChange slot and when the Url is not valid, the state change from "Connecting" to "Closing" but never become "Unconnected". When Url is valid state finishes in "Unconnected"

  10. #10
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp never end

    Quote Originally Posted by didcea View Post
    I mean, I test valid Url with QHttp which works fine, but this same Url ddin't work with socket.
    I dont think so, because QHttp uses QTcpSocket internally.
    Let me assure you, We can send every HTTP command using a TCPSocket. Having socket in hands gives your more power and control.

    Quote Originally Posted by didcea View Post
    I test stateChange slot and when the Url is not valid, the state change from "Connecting" to "Closing" but never become "Unconnected". When Url is valid state finishes in "Unconnected"
    This is strange. I donr know how we can control this. But you can work around like this.
    1. Check for URL is valid using Socket.
    2. Get the URL using HTTP or Socket, whatever easier for you.

  11. #11
    Join Date
    Oct 2008
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp never end

    Ok, thank, I will explore socket solution

Similar Threads

  1. new QHttp() Error
    By fengtian.we in forum Qt Programming
    Replies: 7
    Last Post: 6th October 2010, 17:56
  2. From QHttp to QHttp over SSL
    By Nyphel in forum Newbie
    Replies: 1
    Last Post: 3rd July 2007, 10:41
  3. QHttp with localhost.
    By William Wilson in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2007, 20:26
  4. QHttp download file problem.
    By fengtian.we in forum Qt Programming
    Replies: 12
    Last Post: 12th June 2007, 09:39
  5. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 11:19

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.