[Qt-interest] sockets and threads on linux

markus.goetz at nokia.com markus.goetz at nokia.com
Sun Feb 13 17:48:58 CET 2011


Create the actual object (the QTcpSocket) in the other thread instead of moving it.
________________________________________
From: qt-interest-bounces+markus.goetz=nokia.com at qt.nokia.com [qt-interest-bounces+markus.goetz=nokia.com at qt.nokia.com] On Behalf Of ext pmqt71 [pmqt71 at gmail.com]
Sent: Sunday, February 13, 2011 5:42 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] sockets and threads on linux

Hi all,
Hi Qt people, I hope the best for Qt and you!

I have a tcp client server program working well on WinXP, but not on linux.

MyTcpServer inherits from QTcpServer. the incomingConnection method creates a new socket and moves it to a new thread. The socket is handled by MyTcpSocket that inherits from QTcpSocket and implements the slots to manage client's incoming data:

void MyTcpServer::incomingConnection(int socketDescriptor)
{
   MyTcpSocket *pSocket = new MyTcpSocket();

   if (!pSocket->setSocketDescriptor(socketDescriptor)) {
       qDebug() << "MyTcpServer::incomingConnection:" << pSocket->error();
       return;
   }

   connect(pSocket, SIGNAL(readyRead()), pSocket, SLOT(onReadyRead()));
   connect(pSocket, SIGNAL(disconnected()), pSocket, SLOT(onSocketDisconnect()));

   QThread *th = new QThread(this);
   pSocket->moveToThread(th);

   th->start();
}

On WinXP all is working fine, and I get the readyRead signal as a client writes.
On linux (Ubuntu 9.04 64bit) the readyRead signal is not fired. The incomingConnection is completed with no error, the pSocket objects gets the event ThreadChange related to the moveToThread operation. Nothing else.
How can I debug?
Qt 4.6.2

thanks
pm





More information about the Qt-interest-old mailing list