I am still not clear with certain things.
Maybe this will help me clear doubts. The following is the code of a threaded SSL server.

main.cpp
Qt Code:
  1. #include <QApplication>
  2. #include <QtCore>
  3.  
  4. #include <stdlib.h>
  5.  
  6. #include "server.h"
  7.  
  8. // Number of requests served
  9. quint64 Served = 0;
  10.  
  11. int main(int argc, char *argv[]){
  12.  
  13. QCoreApplication capp(argc, argv);
  14. NServer server;
  15. NServer serverTLS;
  16.  
  17. // Normal Server
  18. if (!server.listen(QHostAddress::Any, 1780)) {
  19. return 2;
  20. }
  21.  
  22. // SSL Server
  23. if (!serverTLS.listen(QHostAddress::Any, 1781)) {
  24. return 2;
  25. }
  26.  
  27. // Set this is a SSL server
  28. serverTLS.isTLS = 1;
  29.  
  30. // Load the certificate
  31. QFile cert("./conf/cert.pem");
  32. if(!cert.open(QIODevice::ReadOnly)){
  33. qDebug() << "Could not open cert.pem";
  34. }
  35.  
  36. serverTLS.Certificate = QSslCertificate(&cert);
  37.  
  38. // Load the KEY
  39. QFile key("./conf/key.pem");
  40. if(!key.open(QIODevice::ReadOnly)){
  41. qDebug() << "Could not open key.pem";
  42. }
  43.  
  44. serverTLS.SslKey = QSslKey(&key, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "123456");
  45.  
  46. // Start the event loop
  47. return capp.exec();
  48.  
  49. }
To copy to clipboard, switch view to plain text mode 

server.h
Qt Code:
  1. #ifndef SERVER_H
  2. #define SERVER_H
  3.  
  4. #include <QtNetwork>
  5. #include <qdebug.h>
  6. #include "thread.h"
  7.  
  8. // The Server Class
  9. class NServer : public QTcpServer
  10. {
  11. Q_OBJECT
  12.  
  13. public:
  14.  
  15. // Constructor
  16. NServer(QObject *parent = 0);
  17.  
  18. // Is this a SSL server ?
  19. int isTLS;
  20.  
  21. // Certificate
  22. QSslCertificate Certificate;
  23.  
  24. // Key
  25. QSslKey SslKey;
  26.  
  27. protected:
  28.  
  29. void incomingConnection(int socketDescriptor);
  30.  
  31. };
  32.  
  33. #endif
To copy to clipboard, switch view to plain text mode 

server.cpp
Qt Code:
  1. #include "server.h"
  2.  
  3. // Constructor
  4. NServer::NServer(QObject *parent) : QTcpServer(parent), isTLS(0) {
  5. // Nothing to do in the constructor
  6. }
  7.  
  8. // All incoming connections are sent to this function
  9. void NServer::incomingConnection(int socketDescriptor){
  10.  
  11. Thread * thread = new Thread(socketDescriptor, this);
  12. //pool.setMaxThreadCount(10000);
  13.  
  14. // Set the SSL Cert and Key if TLS is on
  15. if(isTLS){
  16. thread->isTLS = isTLS;
  17. thread->Certificate = Certificate;
  18. thread->SslKey = SslKey;
  19. }
  20.  
  21. connect(thread->socket, SIGNAL(sslErrors(QList<QSslError>)),
  22. this, SLOT(sslErrors(QList<QSslError>)));
  23.  
  24. connect(thread, SIGNAL(finished()), thread, SLOT(quit()));
  25. //connect(thread, SIGNAL(finished()), thread, SLOT(test()));
  26. connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
  27.  
  28. // Start the thread
  29. thread->start();
  30.  
  31. }
To copy to clipboard, switch view to plain text mode 

thread.h
Qt Code:
  1. #ifndef THREAD_H
  2. #define THREAD_H
  3.  
  4. #include <QThread>
  5. #include <QtNetwork>
  6. #include <qdebug.h>
  7.  
  8. // Thread class
  9. class Thread : public QThread
  10. {
  11. Q_OBJECT
  12.  
  13. public:
  14.  
  15. // Constructor
  16. Thread(int socketDescriptor, QObject *parent);
  17.  
  18. // This is the function which is called on a new connection
  19. void run();
  20.  
  21. // Is it in TLS MODE ?
  22. int isTLS;
  23.  
  24. // Certificate
  25. QSslCertificate Certificate;
  26.  
  27. // Key
  28. QSslKey SslKey;
  29.  
  30. // A socket pointer to the SOCKET so that we can use it to do stuff
  31. QSslSocket * socket;
  32.  
  33. signals:
  34. void error(QTcpSocket::SocketError socketError);
  35.  
  36. private:
  37.  
  38. // The Socket Descriptor
  39. int socketDescriptor;
  40.  
  41. // If the output has started then no header should be allowed
  42. bool outputStarted;
  43.  
  44. // SSL Socket Connection start
  45. bool SSLSocket();
  46.  
  47. // TCP Socket Connection start
  48. bool NormalSocket();
  49.  
  50. // Write Data to the socket
  51. bool socketWrite(const QByteArray &text);
  52.  
  53. // Write a header
  54. bool header(const QByteArray &text);
  55.  
  56. // Write the BODY
  57. bool write(const QByteArray &text);
  58.  
  59. // Write the given BODY and Close the SOCKET as well.
  60. bool end(const QByteArray &text);
  61.  
  62. // Closes the socket
  63. void cleanup();
  64.  
  65. public slots:
  66.  
  67. // Closes the socket
  68. void sslErrors(const QList<QSslError> &errors);
  69.  
  70. // SSL Socket Connection start
  71. void handshakeComplete();
  72.  
  73. void test();
  74.  
  75. };
  76.  
  77. #endif
To copy to clipboard, switch view to plain text mode 

thread.cpp
Qt Code:
  1. #include "thread.h"
  2.  
  3. extern quint64 Served;
  4.  
  5. // Constructor
  6. Thread::Thread(int socketDescriptor, QObject *parent)
  7. : QThread(parent), socketDescriptor(socketDescriptor)
  8. {
  9. this->isTLS = 0;
  10. this->setTerminationEnabled(true);
  11.  
  12. qDebug() << "Socket" << socketDescriptor;
  13.  
  14. //qDebug()<< QThread::idealThreadCount();
  15. }
  16.  
  17. void Thread::test(){
  18. qDebug() << "Finished";
  19. }
  20.  
  21. // When its a normal connection
  22. bool Thread::NormalSocket(){
  23.  
  24. // Create the Socket
  25. socket = new QSslSocket;
  26.  
  27. if (!socket->setSocketDescriptor(socketDescriptor)) {
  28. emit error(socket->error());
  29. delete socket;
  30. return false;
  31. }
  32.  
  33. //qDebug() << "In Normal Socket";
  34.  
  35. return true;
  36.  
  37. }
  38.  
  39. // SSL Connection hence SSL Socket
  40. bool Thread::SSLSocket(){
  41.  
  42. // Create the Socket
  43. socket = new QSslSocket;
  44.  
  45. //qDebug() << Certificate;
  46. //qDebug() << SslKey;
  47.  
  48. connect(socket, SIGNAL(encrypted()),
  49. this, SLOT(handshakeComplete()));
  50.  
  51. connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
  52. this, SLOT(sslErrors(QList<QSslError>)));
  53.  
  54. // Set the protocol and certificates
  55. socket->setProtocol(QSsl::AnyProtocol);
  56. socket->setLocalCertificate(Certificate);
  57. socket->setPrivateKey(SslKey);
  58.  
  59. // Set the descriptor
  60. if (!socket->setSocketDescriptor(socketDescriptor)) {
  61. emit error(socket->error());
  62. delete socket;
  63. return false;
  64. }
  65.  
  66. // No need to verify the peer
  67. socket->setPeerVerifyMode(QSslSocket::VerifyNone);
  68.  
  69. // Start the encryption
  70. socket->startServerEncryption();
  71.  
  72. // Wait for the excryption to start
  73. socket->waitForEncrypted(1000);
  74.  
  75. return true;
  76.  
  77. }
  78.  
  79. // Called when the thread is started
  80. void Thread::run(){
  81.  
  82. //this->exec();
  83.  
  84. Served++;
  85. qDebug() << "Num Req : " << Served;
  86.  
  87. // SSL Socket Start
  88. if(isTLS > 0){
  89.  
  90. qDebug() << "SSL";
  91. if(!SSLSocket()){
  92. return;
  93. }
  94.  
  95. // Normal Socket
  96. }else{
  97.  
  98. if(!NormalSocket()){
  99. return;
  100. }
  101.  
  102. }
  103.  
  104. // Wait for it to become read ready for a MAX of 1 second
  105. socket->waitForReadyRead(1000);
  106. //qDebug()<<"Wait";
  107. QMap<QByteArray, QByteArray> headers;
  108. QByteArray reqType;
  109.  
  110. //qDebug() << "Enc : " << socket->isEncrypted();
  111. //qDebug() << "Errors : " << socket->sslErrors();
  112.  
  113. /////////////////////////////////////
  114. // Determine its an DATA / HTTP Call
  115. /////////////////////////////////////
  116.  
  117. // Get the Request Header
  118. req = socket->read(81920);
  119. //req = socket->readAll();
  120. //qDebug() << "Req : " << req;
  121.  
  122. QByteArray block = "HTTP/1.0 200 Ok\r\n"
  123. "Content-Type: text/html; charset=\"utf-8\"\r\n"
  124. "\r\n"
  125. "<form method=\"post\" action=\"\" name=\"input\">"
  126. "<input type=\"text\" value=\"test\">"
  127. "<input type=\"submit\" value=\"test\">"
  128. "</form>\n"
  129. "Test"
  130. "\r\n"
  131. "\r\n"
  132. "\r\n";
  133.  
  134. this->write(block);
  135.  
  136. /*unsigned char * test = (unsigned char *)malloc(134217728);
  137.   this->sleep(10);
  138.   free(test);*/
  139.  
  140. //this->write(block);
  141.  
  142. cleanup();
  143.  
  144. //delete socket;
  145.  
  146. //emit finished();
  147.  
  148. }
  149.  
  150. bool Thread::socketWrite(const QByteArray &text){
  151.  
  152. socket->write(text);
  153.  
  154. return socket->flush();
  155.  
  156. }
  157.  
  158. void Thread::cleanup(){
  159.  
  160. socket->disconnectFromHost();
  161. if(socket->state() != QAbstractSocket::UnconnectedState){
  162. socket->waitForDisconnected();
  163. }
  164.  
  165. //qDebug() << "Cleaned";
  166.  
  167. // Clear the socket
  168. delete socket;
  169.  
  170. // Delete the thread
  171. //this->exit(0);
  172. //this->wait();
  173. //this->deleteLater();
  174.  
  175. }
  176.  
  177. bool Thread::header(const QByteArray &text){
  178.  
  179. if(outputStarted){
  180. return false;
  181. }
  182.  
  183. return this->socketWrite(text);
  184.  
  185. }
  186.  
  187.  
  188. bool Thread::write(const QByteArray &text){
  189.  
  190. // Set that output has been started
  191. outputStarted = true;
  192.  
  193. return this->socketWrite(text);
  194.  
  195. }
  196.  
  197.  
  198. bool Thread::end(const QByteArray &text){
  199.  
  200. // Set that output has been started
  201. outputStarted = true;
  202.  
  203. return this->socketWrite(text);
  204.  
  205. }
  206.  
  207. // Called when there are SSL errors
  208. void Thread::sslErrors(const QList<QSslError> &errors){
  209. foreach (const QSslError &error, errors){
  210. qDebug() << "[Backup::sslErrors] " << error.errorString();
  211. }
  212.  
  213. // Ignore Errors
  214. //socket->ignoreSslErrors();
  215. }
  216.  
  217. // SSL handshake complete
  218. void Thread::handshakeComplete(){
  219. qDebug() << "[Thread::handshakeComplete]";
  220. }
To copy to clipboard, switch view to plain text mode 

When I run this application I get an error as follows :
QObject::connect: Cannot queue arguments of type 'QList<QSslError>'
(Make sure 'QList<QSslError>' is registered using qRegisterMetaType().)
I am not able to understand why is this so ?
What is the corrective code for this ?