title: How to use the TLS protocol on Qt?
body: <p>Please give an example of the server side, which shows use TLS.</p>
  
  <p>Now I have the following code:</p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  #include "server.h"
  
  int main(int argc, char *argv[]) {
      QCoreApplication a(argc, argv);
      Server h;
      return a.exec();
  }
  
  ///////////////////////////////////////
  
  #ifndef SERVER_H
  #define SERVER_H
  
  #include &lt;QTcpServer&gt;
  
  class Server : public QTcpServer {
      public:
      Server();
  
      void incomingConnection(int);
  };
  
  #endif // SERVER_H
  
  
  ///////////////////////////////////////////
  
  #include "server.h"
  
  #include &lt;QSslSocket&gt;
  #include &lt;QSslCertificate&gt;
  
  Server::Server() {
      if (!listen(QHostAddress::Any, 80)) {
          //error
      }
  }
  
  void Server::incomingConnection(int d) {
      QSslSocket * socket = new QSslSocket();
      if(socket-&gt;setSocketDescriptor(d)) {
          QString c, k;
          c = "site.crt";
          k = "site.key";
          socket-&gt;setLocalCertificate(c);
          socket-&gt;setPrivateKey(k);
          socket-&gt;startServerEncryption();
          if(socket-&gt;waitForEncrypted()) {
              if(socket-&gt;waitForReadyRead()) {
                  socket-&gt;write(socket-&gt;readAll());
                  socket-&gt;waitForBytesWritten();
                  socket-&gt;disconnectFromHost();
                  if(socket-&gt;state() == QTcpSocket::UnconnectedState) {
                      socket-&gt;waitForDisconnected();
                  }
                  socket-&gt;close();
                  socket-&gt;deleteLater();
              }
              else {
                  delete socket;
              }
          }
          else {
              delete socket;
          }
      }
  }
  </code></pre>
  
  <p>How can I change it to first use protocol TLS, and then SSL?</p>
  
  <p>Common task is to write a server with support for SNI.</p>