Bernie
17th February 2011, 10:43
Hi,
at the moment I try to program a TcpServer and i would like to thread the socket.
So my code looks like this:
void Server::incomingConnection(int socketId)
{
socket = new ClientSocket;
socket->setSocketDescriptor(socketId);
QThread *socketThread = new QThread;
socket->moveToThread(socketThread);
socketThread->start();
}
With this code I expected two threads. One main thread and another for my ClientSocket. But using
qDebug() << QThread::currentThreadId;
returns always the same ThreadID (in Server and ClientSocket class).
What am I doing wrong? Or am I using currentThreadId wrong?
Thanks for your help.
Bernie
at the moment I try to program a TcpServer and i would like to thread the socket.
So my code looks like this:
void Server::incomingConnection(int socketId)
{
socket = new ClientSocket;
socket->setSocketDescriptor(socketId);
QThread *socketThread = new QThread;
socket->moveToThread(socketThread);
socketThread->start();
}
With this code I expected two threads. One main thread and another for my ClientSocket. But using
qDebug() << QThread::currentThreadId;
returns always the same ThreadID (in Server and ClientSocket class).
What am I doing wrong? Or am I using currentThreadId wrong?
Thanks for your help.
Bernie