Hi,

I am trying to get a QSslSocket to work in QThread but I cant seem to get it to work.
The following is the code :
Qt Code:
  1. // Local includes
  2. #include "main.h"
  3.  
  4. // Constructor of the timer class
  5. Timer::Timer(QObject *parent) : QObject(parent)
  6. {
  7. qDebug() << "inConstrutor";
  8. QTimer *timer = new QTimer();
  9. connect(timer, SIGNAL(timeout()), this, SLOT(startBackup()));
  10. timer->start(5000);
  11. }
  12.  
  13. // Start the backup
  14. int Timer::startBackup(){
  15.  
  16. qDebug() << "inStart" << backingUP;
  17. //return 0;
  18.  
  19. if(backingUP){
  20. return 2;
  21. }
  22.  
  23. // Start the backup thread
  24. Backup *backup = new Backup();
  25.  
  26. // Make a connection for deleting this later when done
  27. //connect(backup, SIGNAL(finished()), backup, SLOT(deleteLater()));
  28.  
  29. // Set that we are running ATM
  30. backingUP = true;
  31.  
  32. backup->start();
  33.  
  34. return 1;
  35.  
  36. }
  37.  
  38. // The constructor
  39. Backup::Backup(QObject *parent)
  40. : QThread(parent)
  41. {
  42.  
  43. // This thread can never be terminated
  44. //this->setTerminationEnabled(false);
  45. }
  46.  
  47. // The function that does everything
  48. void Backup::run()
  49. {
  50.  
  51. this->doit();
  52.  
  53. }
  54.  
  55.  
  56. void Backup::doit(){
  57.  
  58. qDebug() << "Doit";
  59.  
  60. socket = new QSslSocket;
  61.  
  62. connect(socket, SIGNAL(readyRead()),
  63. this, SLOT(socketReadyRead()));
  64. connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
  65. this, SLOT(sslErrors(QList<QSslError>)));
  66. connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
  67. this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
  68. connect(socket, SIGNAL(encrypted()),
  69. this, SLOT(socketEncrypted()));
  70.  
  71. // Connect to the server
  72. socket->connectToHostEncrypted(NSettings->value("hostname").toString(), NSettings->value("port").toInt());
  73.  
  74. // Wait for it to reach the encryted and connected state
  75. if (!socket->waitForEncrypted()) {
  76. qDebug() << "waitForEncrypted Error";
  77. return; // An error occured
  78. }
  79.  
  80. // This is the protocol
  81. socket->write("ENTERHEADER\r\n");
  82. socket->waitForBytesWritten();
  83.  
  84. QByteArray username = NSettings->value("user").toByteArray();
  85. QByteArray device = NSettings->value("device").toByteArray();
  86.  
  87. // We first need to LOGIN
  88. this->rite("L"+ username.toBase64() +" "+ device.toBase64());
  89. socket->waitForBytesWritten();
  90.  
  91. }
  92.  
  93. // Called whenever there is something to READ in the buffer
  94. void Backup::socketReadyRead(){
  95.  
  96. qDebug() << socket->bytesAvailable();
  97. QString str = socket->readAll();
  98. qDebug() << str;
  99.  
  100. bool unconnected = !socket || socket->state() == QAbstractSocket::UnconnectedState;
  101.  
  102. if(str == "LOGIN SUCCESSFUL"){
  103.  
  104. for(int i = 1; i <= 1000; i++){
  105.  
  106. // Was the login successful ?
  107. if(unconnected){
  108. qDebug() << socket->state();
  109. return;
  110. }
  111.  
  112. this->rite("STORE ABC\r\n");
  113. socket->waitForBytesWritten();
  114. }
  115.  
  116. }
  117.  
  118. qDebug() << "End READ";
  119.  
  120. // Disconnect from the server
  121. //socket->disconnectFromHost();
  122.  
  123. }
  124.  
  125. // Called when the connection is fully established
  126. void Backup::socketEncrypted()
  127. {
  128. qDebug() << "Connection Established";
  129. }
  130.  
  131. // Called when there are SSL errors
  132. void Backup::sslErrors(const QList<QSslError> &errors)
  133. {
  134. foreach (const QSslError &error, errors){
  135. qDebug() << error.errorString();
  136. }
  137.  
  138. // Ignore Errors
  139. socket->ignoreSslErrors();
  140. }
  141.  
  142. // Whenever there is a change in the connection STATE, this is called
  143. void Backup::socketStateChanged(QAbstractSocket::SocketState state)
  144. {
  145. qDebug() << state;
  146. }
  147.  
  148. // Socket write safe as it appends the length to the beginning of the string
  149. qint64 Backup::rite(const QByteArray & data)
  150. {
  151. return socket->write(data);
  152. }
To copy to clipboard, switch view to plain text mode 

When I run this I get the following error :
Qt Code:
  1. inConstrutor
  2. inStart false
  3. Doit
  4. QObject::connect: Cannot queue arguments of type 'QAbstractSocket::SocketState'
  5. (Make sure 'QAbstractSocket::SocketState' is registered using qRegisterMetaType().)
  6. waitForEncrypted Error
To copy to clipboard, switch view to plain text mode 

If I dont call the backup->start(); and call the backup->doit(); then the code works perfectly.
I would really be happy, if someone can shed any light on what I am doing wrong.