Your already storing it in local scope (QTcpSocket* socket), what you need to do is store it in a more global scope, such as in your class. Just assign, eg. clientSock = socket;