Hey guys i have a small question.

I would like to connect with several servers by using one thread with different
sockets. It works for one socket but doesnt connect with the other server.

TCP: is the name of the thread.

Qt Code:
  1. ...
  2. header
  3. ...
  4.  
  5. QTcpSocket *socket[10];
  6. ...
  7. ...
  8. source
  9. ...
  10.  
  11. void TCP::run()
  12. {
  13. initSocket();
  14. }
  15.  
  16. void TCP::initSocket()
  17. {
  18. for(int i=0;i<2;i++)
  19. {
  20. socket[i] = new QTcpSocket();
  21.  
  22. connect(socket[i], SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection);
  23. connect(socket[i], SIGNAL(connected()),this, SLOT(connected()), Qt::DirectConnection);
  24. connect(socket[i], SIGNAL(disconnected()),this, SLOT(stopConnection()), Qt::DirectConnection);
  25. connect(socket[i], SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64)));
  26.  
  27. startConnection(i);
  28. }
  29. exec();
  30. }
  31.  
  32.  
  33. void TCP::startConnection(int conNUM)
  34. {
  35. QHostAddress addr(address[conNUM]);
  36. socket[conNUM]->connectToHost(addr, port[conNUM]);
  37. }
  38.  
  39. .....
To copy to clipboard, switch view to plain text mode 

Thanks