Results 1 to 19 of 19

Thread: QTcpSocket::connectToHost

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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 QTcpSocket::connectToHost

    Hello All,

    I am trying to connect using QTcpSocket::connectToHost. This is working fine when I provide host IP (tcpSocket->connectToHost("xx.xx.xx.xx".80)).

    But not working when I provide host name (tcpSocket->connectToHost("www.xxx.com".80)).
    It seems it not resolving host name.
    What can I do ?

  2. #2
    Join Date
    May 2008
    Posts
    58
    Thanks
    2

    Default Re: QTcpSocket::connectToHost

    from Qt's document, it should support host name,
    Could you try : "At any point, the socket can emit error() to signal that an error occurred. "
    to get detailed error information?

  3. #3
    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: QTcpSocket::connectToHost

    Its always giving same error. "host not found".

  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

    Default Re: QTcpSocket::connectToHost

    I found one more problem with QTcpSocket class.
    When we set proxy settings in this class, we need to call QTcpSocket::setProxy(QNetworkProxy("HOST NAME", PORT));

    But this is not working at all. Means its setting the proxy but not using that.
    It means
    case 1:
    Proxy server is there("xyz",3128).
    QTcpSocket soc;
    soc.setProxy(QNetworkProxy("xyz", 3128));
    soc.connectToHost("100.100.100.100", 80);

    case 2:
    Proxy server is not there.
    QTcpSocket soc;
    soc.connectToHost("100.100.100.100", 80);

    case 3:
    Proxy server is there("xyz",3128).
    QTcpSocket soc;
    soc.setProxy(QNetworkProxy("xyz", 3128));
    soc.connectToHost("www.yahoo.com", 80);

    case 4:
    Proxy server is not there.
    QTcpSocket soc;
    soc.connectToHost("www.yahoo.com", 80);



    In this scenario only case 2 will work.
    Case 2 will only work because there is no proxy server and we provide IP address instead of host name in function connectToHost.



    So there are 2 issues with TCP Socket.

    1. Resolving host name e.g soc.connectToHost("www.yahoo.com", 80);
    2. Use proxy settings done by e.g. soc.setProxy(QNetworkProxy("xyz", 3128));
    Last edited by yogeshgokul; 11th September 2008 at 14:38.

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

    Default Re: QTcpSocket::connectToHost

    Does it work if you specify the proxy's IP address instead of its name? It looks like name resolution doesn't work on your system.

  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: QTcpSocket::connectToHost

    I also thought that and tried already but no luck. I forget to mention that case here.

  7. #7
    Join Date
    Apr 2009
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpSocket::connectToHost

    Today I encounter the same problem!if I use the host name,always the error:host not found!But when I use the IP address,such as :xx.xx.xx.xx,it work perfectly!I don‘t know why

  8. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTcpSocket::connectToHost

    hey yogesh!! ... are u still stuck with the problem we faced at PSPL??? as far as i remember when we were coding SM2 and working on upload/download muhurta u faced the same problem...

    remember PM told that we have hardcoded the website ip in fndef file ...

    this remided me of old days... jeevan me chai gala sek kar peene ka maja he kuch aur tha..


  9. #9
    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: QTcpSocket::connectToHost

    Yes this is same problem, but now resolved in latest qt build 4.5.X. ha yaar wo din to mast hi the jab appan 3 din me apps bana ke fek dete the.. iski maka naka kar dete the

  10. #10
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTcpSocket::connectToHost

    mujhe to ab bhi lagta hai ki hum 3 din me app bana ke pani ka gilaas manager ke muh pe mar sakte hain

  11. #11
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTcpSocket::connectToHost

    aur jab wo apni aankhe mal raha hoga to kya kehna/karna chahiye?

  12. #12
    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: QTcpSocket::connectToHost

    uska haath aakho pe se hata ke, kheech ke lappad laga te hai,

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.