Results 1 to 5 of 5

Thread: QTcpSocket and Qt 4.2.3

  1. #1
    Join Date
    May 2007
    Posts
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTcpSocket and Qt 4.2.3

    Some time ago I began developing a socket-using program with Qt 4.2.2. I've recently switched to a new computer and installed the more recent Qt 4.2.3.

    My code compiles and runs under both systems, but the tcp socket doesn't function properly on the 4.2.3 system.

    The code is:

    #include <QApplication>
    #include <QTcpSocket>
    #include <iostream>

    int main(int argc, char* argv[])
    {
    QApplication app(argc, argv);
    QTcpSocket *internet = new QTcpSocket;
    internet->connectToHost("xxx.xxx.xxx.xxx", xxxx);
    std::cout << "waiting up to 10s for connection..." << std::endl;
    if(internet->waitForConnected(10000))
    std::cout << "Connected to host!" << std::endl;
    else
    {
    std::cout << "Could not connect to host!" << std::endl;
    exit(0);
    }
    //more code here//
    }
    Under 4.2.3, I always exit after "Could not connect to host!" while on my 4.2.2 setup, the connection is established properly.

    This is the most basic socket implementation, right? This shouldn't be hard to implement, so I must be doing something stupid. What's my mistake?

    Thanks for your time.
    Last edited by slcotter; 9th May 2007 at 01:01. Reason: formatting & shortened snippet

  2. #2
    Join Date
    May 2007
    Posts
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpSocket and Qt 4.2.3

    I suppose it's worth noting that the connection is rejected with the error message: "ConnectionRefusedError" or, if you prefer, zero.

  3. #3
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTcpSocket and Qt 4.2.3

    Well, you've got two different factors going on here: a new computer, and 4.2.2/4.2.3. Have you tried installing 4.2.2 on your new computer, and/or tried 4.2.3 on your old computer? This might help tell you if it's really due to 4.2.3 or if it's something with your new computer's settings. Firewall settings are always good to double check.
    Software Engineer



  4. #4
    Join Date
    Aug 2006
    Location
    Switzerland
    Posts
    52
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpSocket and Qt 4.2.3

    Can you telnet from your new computer to the host and port you are trying to connect to in your program?
    The Wheel weaves as the Wheel wills.

  5. #5
    Join Date
    May 2007
    Posts
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpSocket and Qt 4.2.3

    The more I look into it today, the more I realize it's a Fedora Core 6 issue than it is a Qt issue. Thanks for the time and sorry for posting this here prematurely.

    Fun fact: If I execute my program several times several times in rapid succession, it'll execute properly. It will never succeed if I execute it once or several times in slow succession.

Similar Threads

  1. Tell QTcpSocket which interface to use
    By rianquinn in forum Qt Programming
    Replies: 7
    Last Post: 23rd December 2010, 17:28
  2. How do I use QTcpSocket properly ?
    By mnemonic_fx in forum Qt Programming
    Replies: 13
    Last Post: 29th March 2007, 20:33
  3. Problems with QThread and QTcpSocket
    By cookiem in forum Qt Programming
    Replies: 6
    Last Post: 2nd November 2006, 08:25
  4. Problem with QTcpSocket and QDataStream
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 16th September 2006, 13:08
  5. QTcpSocket disconnection problem
    By erdi in forum Qt Programming
    Replies: 4
    Last Post: 19th February 2006, 21:50

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.