PDA

View Full Version : QTcpSocket in QThread Problem In Qt5.1



alizadeh91
19th August 2013, 15:42
I’ve created a QThread and in run method i have a QTcpSocket variable. It successfully send data to the client. But when the program exit from run function, and I create another thread with the same socket descriptor it fails to send data. The error is : “Invalid Socket Descriptor”. It seems that the first QTcpSocket is not deleted correctly and it uses the port so the second thread with the same port can not open it. Please Advice.

anda_skoa
20th August 2013, 09:03
it is more likely that the first QTcpSocket instance is in fact deleted correctly and has thus closed the file descriptor associated with the socket.

Why would you want to use the same socket in two threads and not just use one thread per connection?
Or actually, why use threads at all?

Cheers,
_