Is it possible for a QTcpSocket to release its descriptor so ownership over the socket can be transferred to another QTcpSocket object on a different thread, or to a QSslSocket, without closing/interrupting the socket?
socket1.setDescriptor(descriptor);
// .....
descriptor = socket1.descriptor();
socket1.release(); // <--- Is there a way to do this?
socket2.setSocketDescriptor(descriptor);
No, you can’t release a socket descriptor once it has been assigned to a
QTcpSocket.But I’m not sure you would need to. The
QTcpSocketcan usually be moved to another thread withmoveToThread, the constraints are the same as any movedQObject:moveToThreadshould be called inside the thread to which the object currently belongs,theObject->setParent(0);, or move the parent instead of the object),and because it is a
QTcpSocket, the receiving thread should be running an event loop or you need to use thewaitFor...functions in that thread.This note seems to suggest that this only works for sockets since Qt 4.7.