Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved QTcpServer Base class

    General and Desktop
    inheritance abstract class qtcpserver
    2
    3
    753
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • moffa13
      moffa13 last edited by

      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 :

      if(m_ssl){
          socket = dynamic_cast<SSLServer*>(m_tcpServer)->nextPendingConnection();
      }else{
          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 !

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        @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?

        1 Reply Last reply Reply Quote 1
        • moffa13
          moffa13 last edited by

          @mrjj said:

          but does QSslSocket not inherited QTcpSocket ?

          Yes, you're right thank you !

          1 Reply Last reply Reply Quote 1
          • First post
            Last post