All I want to do is create a websocket client connection using Qt on a thread. Create a processing thread,so that when data comes to the websocket handler the data is passed(through slots and signals) to the processor and then the processor processes the data and passes it to the main-thread(again via signals and slots) to render the data.All I am doing this because I want to keep the main thread ublocked because processing and websocket data would take lot of time. First of all,is this the right approach?
Second:when I try to run QWebsockets on a different thread I am getting the error .
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QWebSocket(0x1a493f30), parent's thread is QThread(0x187fc0e8), current thread is QThread(0xe3fe08)
Not sure where to include or put this
(Make sure 'QAbstractSocket::SocketState' is registered using qRegisterMetaType().)
in my example. The code which I am using are.

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6.  
  7. QUrl url("ws://localhost:8080");
  8. websocketObj=new websocketclientimpl(url);
  9. websocketObj->moveToThread(&workerThread_websocket);
  10. connect(&workerThread_websocket, &QThread::started, websocketObj, &websocketclientimpl::startConnection);
  11. workerThread_websocket.start();
  12. QMainWindow::showMaximized();
  13.  
  14. }
  15.  
  16. MainWindow::~MainWindow()
  17. {
  18. delete ui;
  19. workerThread_websocket.quit();
  20. workerThread_websocket.wait();
  21. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. websocketclientimpl::websocketclientimpl(const QUrl &url){
  2. this->m_url=url;
  3. }
  4.  
  5. void websocketclientimpl::startConnection()
  6. {
  7. qDebug() << "WebSocket client:" << m_url;
  8. connect(&m_webSocket, &QWebSocket::connected, this, &websocketclientimpl::onConnected);
  9. connect(&m_webSocket, &QWebSocket::disconnected, this, &websocketclientimpl::onClosed);
  10. QNetworkRequest request=QNetworkRequest(QUrl(m_url));
  11. m_webSocket.open(request);
  12.  
  13. }
  14.  
  15. void websocketclientimpl::stopConnection(){
  16. m_webSocket.disconnect();
  17. qDebug() << "WebSocket stopped";
  18. }
  19.  
  20. void websocketclientimpl::onConnected()
  21. {
  22. qDebug() << "WebSocket connected..";
  23. }
  24.  
  25. void websocketclientimpl::onClosed()
  26. {
  27.  
  28. }
  29.  
  30. void websocketclientimpl::onTextMessageReceived(QString message)
  31. {
  32. qDebug() << "message received in websocket class"<<message;
  33. emit processIncomingMessage(message);
  34. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. using namespace std;
  2. namespace Ui {
  3. class MainWindow;
  4. }
  5.  
  6. class MainWindow : public QMainWindow
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11. explicit MainWindow(QWidget *parent = 0);
  12. ~MainWindow();
  13.  
  14. private:
  15. Ui::MainWindow *ui;
  16. websocketclientimpl *websocketObj;
  17. calculation *calculationObj;
  18.  
  19. QThread workerThread_websocket;
  20. QThread workerThread_calculator;
  21.  
  22. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. class websocketclientimpl : public QObject
  2. {
  3. Q_OBJECT
  4. public:
  5. QWebSocket m_webSocket;
  6. websocketclientimpl(const QUrl &url);
  7. void startConnection();
  8. void stopConnection();
  9.  
  10. private Q_SLOTS:
  11. void onConnected();
  12. void onClosed();
  13. void onTextMessageReceived(QString message);
  14.  
  15. Q_SIGNALS:
  16. void processIncomingMessage(QString message);
  17.  
  18. private:
  19.  
  20. QUrl m_url;
  21. };
To copy to clipboard, switch view to plain text mode 

Can anyone please help me out here? Stuck very badly!