QTcpServer Base class

  • Hello,

    I'm creating an http server who can handle ssl or non ssl connections (boolean in the constructor) and I wanted to use either QTcpServer or SSLServer (class created by myself which inherits from QTcpServer) without changing my code

    So let's admit I have to do nextPendingConnection(); I don't want to do this :

        socket = dynamic_cast<SSLServer*>(m_tcpServer)->nextPendingConnection();
        socket = m_tcpServer->nextPendingConnection();

    but only m_tcpServer->nextPendingConnection(); and get the right type (either QTcpSocket or QSslSocket)

    So actually I think it's possible because I use functions existing in both classes but I don't know how to do achieve this.

    Thank you !

  • Qt Champions 2016

    @moffa13 said:

    QTcpSocket or QSslSocke

    but does QSslSocket not inherited QTcpSocket ?

    So if socket is
    QTcpSocket *socket

    it could point to a QSslSocke also and the correct nextPendingConnection() would be called
    pr normal resolve?

  • @mrjj said:

    but does QSslSocket not inherited QTcpSocket ?

    Yes, you're right thank you !

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.