View Full Version : Cannot send data with QTcpSocket

1st September 2012, 11:24

With Qt 4.8 under win32, I'm trying to send data to a tcp server

QTcpSocket sck;

sck.connectToHost(myip, 7800);

if (sck.waitForConnected(8000)==false)
return -1;

Connection works pretty well (I see it on the server)
But now

ret = sck.write("test data sending");

ret returned 17, cool...

But on server side, I received... nothing !?

(If I do the same thing in "pure" C socket, it works !?)

What am I doing wrong ?

Thanks for you help...

1st September 2012, 11:43
QTcpSocket sct;

This might be your problem. Does the object live long enough?

1st September 2012, 11:45
Yes I'm sorry, wrong typo... Anyway problem remains :)

1st September 2012, 11:50
I didn't see the typo. But this isn't what I meant.
You created the socket on the stack, which means it gets destroyed at the end of the function. Since sockets are asynchronous, the data might not have been sent already at the moment the socket object is destroyed.

1st September 2012, 12:15
Ok, I put it into a class, same problem

(Even with the debugger I've got the issue)


1st September 2012, 12:33
Try using a network analyzer. This will give you a lot more insight into the actual network traffic.

I don't know what you mean with "Even with the debugger I've got the issue".

Edit: Also try to use the error signal to see if there's an error.

1st September 2012, 13:00
Thanks for you answer,
Indeed I wasn't very clear. It was just to say it wasn't an issue with the stack.

And yes, my last chance is wireshark :)