Hi everyone,

I have found a strange behavior by QTcpSocket working on it.
The explanation isn't easy, but I'll try it anyway.

The idea was to create a thread in the application that works with a QTcpSocket to, of course, connect to a server.

So, subclass QThread, and there what is needed for the socket.

Now, depending on how and where QTcpSocket is declared, connection is successful or not.
Details:
considering the same code to connect, that is a simple
Qt Code:
  1. socket->connectToHost("someserver",someport);
To copy to clipboard, switch view to plain text mode 
let's change the QTcpSocket declaration.

1) as a local variabile in run() (QThread::run() reimplementation)
Qt Code:
  1. QTcpSocket socket;
  2. socket.connectToHost("server...",port);
To copy to clipboard, switch view to plain text mode 
and in this way works fine.

2) as a dinamically a allocated pointer in thread class (member pointer)
Qt Code:
  1. class mysocketthread:public QThread
  2. {
  3. private:
  4. QTcpSocket *socket;
  5. ...
  6. };
  7.  
  8. mysocketthread::mysocketthread()
  9. {
  10. socket=new QTcpSocket();
  11. ...
  12. }
  13.  
  14. void mysocketthread::run()
  15. {
  16. socket->connectToHost("server...",port);
  17. ...
  18. }
To copy to clipboard, switch view to plain text mode 
and in this way keeps failing the connection, giving a constant "Connection refused".

Maybe I'm missing something, but I think of this as quite strange... isn't it?