PDA

View Full Version : QTcpSocket and Qt 4.2.3



slcotter
9th May 2007, 01:59
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.

slcotter
9th May 2007, 02:11
I suppose it's worth noting that the connection is rejected with the error message: "ConnectionRefusedError" or, if you prefer, zero.

gfunk
9th May 2007, 07:54
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.

danadam
9th May 2007, 09:22
Can you telnet from your new computer to the host and port you are trying to connect to in your program?

slcotter
9th May 2007, 17:14
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.