Search code examples
c++qt4

Is there a way to use a QTcpSocket with an existing socket?


I use a library that returns a handle to a socket. Once I have that handle, I need to read and write from it. I'd rather use QTcpSocket as it's easier than using read()/write(). Is there a way to use QTcpSocket with an already opened socket rather than have QTcpSocket open the socket?


Solution

  • Maybe you can use QTcpSocket with an exisiting socket descriptor :

    QTcpSocket* socket = new QTcpSocket();
    socket->setSocketDescriptor(socketDesc); // socketDesc is a pointer of  type   qintptr 
    

    and now you can read and write into socket