Hi there,

I'm having a problem with reading an incomming connection on my QTcpServer.

i create a QtcpServer object and connect the signal newconnection() to a custom made slot:
Qt Code:
  1. serv = new QTcpServer();
  2. connect(serv, SIGNAL(newConnection()), this, SLOT(newsession()));
  3. serv->listen(QHostAddress::Any, port);
To copy to clipboard, switch view to plain text mode 

then from the slot for each pending connection i create a thread to handle the incomming data:
Qt Code:
  1. void clienthandler::newsession()
  2. {
  3. QThread *t;
  4. incomingslientsession *client;
  5. while(serv->hasPendingConnections()){
  6. t = new QThread();
  7. client = new incomingslientsession(&db, serv->nextPendingConnection()->socketDescriptor(), &mutex);
  8. connect(t, SIGNAL(started()), client, SLOT(dowork()));
  9. connect(t, SIGNAL(finished()), t, SLOT(deleteLater())); // Delete thread after session is handeled
  10. client->moveToThread(t);
  11. t->start();
  12. }
  13. }
To copy to clipboard, switch view to plain text mode 
In the thread i create a new Qtcpsocket() and assign the given socketdescriptor. After that i try to read 20 bytes from the incomming stream (sending node sends 1000+ bytes)
Qt Code:
  1. sock.setSocketDescriptor(socketdescriptor);
  2.  
  3. // Test code to read some bytes
  4. int bytesRead = 0;
  5. while (bytesRead < 20) // First 20 bytes
  6. bytesRead = sock.read(buff.data(), 20-bytesRead);
  7.  
  8. qDebug() << buff;
To copy to clipboard, switch view to plain text mode 

This is where the problem is, the socket never receives any bytes so this code gets stuck in an endless loop! i can see the data coming in when looking with wireshark and the socketdescriptor is also the right one.

Can anyone see the problem here?

Thanks,

Sisco