I created two classes of FServer heir of QTcpServer and FThread from QThread. When you connect a new customer creates a separate thread, and it passes the handle to the socket.
Code:
void FServer::incomingConnection(int socketDescriptor) { FThread *thread = new FThread(socketDescriptor, this); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); } //SLOT { arraySockets.push_back(socket); qDebug() << "FServer -> tcpSocket" << socket->thread(); }
The code runs in a separate thread:
Code:
void FThread::run() { if (!tcpSocket->setSocketDescriptor(socketDescriptor)) { emit error(tcpSocket->error()); return; } //My code ............... emit createNewSocket(tcpSocket); qDebug() << "FThread -> tcpSocket" << tcpSocket->thread(); tcpSocket->waitForDisconnected(); }
Error:
Text error:
Why I can not I move objects in the main thread?
-------------------------
I came to the conclusion that everything can be processed without the use of threads.
Closed. Thank you.