Set parent of internal server objects
authorPeter Kümmel <syntheticpp@gmx.net>
Sat, 2 Aug 2014 12:48:32 +0000 (14:48 +0200)
committerPeter Kümmel <syntheticpp@gmx.net>
Tue, 18 Nov 2014 17:57:44 +0000 (18:57 +0100)
After moving the websocket server into another thread
current code doesn't work because then the QTcpServer/QSslServer
objects reside in a different thread:
"QWarning: QObject: Cannot create children for a parent that is in a different thread."

QObject::moveToThread(QThread*) also moves QObjects's children, therefore the
internal server objects need to be children of QWebSocketServer.

Change-Id: Ic7e8a564cd87400a4ab7258e3799157ed359c098
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
src/websockets/qwebsocketserver.cpp
src/websockets/qwebsocketserver_p.cpp

index 59cfd89..b7368b3 100644 (file)
@@ -247,6 +247,8 @@ QWebSocketServer::QWebSocketServer(const QString &serverName, SslMode secureMode
  */
 QWebSocketServer::~QWebSocketServer()
 {
+    Q_D(QWebSocketServer);
+    d->close(true);
 }
 
 /*!
index 28f9bea..77caa51 100644 (file)
@@ -74,7 +74,7 @@ QWebSocketServerPrivate::QWebSocketServerPrivate(const QString &serverName,
 void QWebSocketServerPrivate::init()
 {
     if (m_secureMode == NonSecureMode) {
-        m_pTcpServer = new QTcpServer();
+        m_pTcpServer = new QTcpServer(q_ptr);
         if (Q_LIKELY(m_pTcpServer))
             QObjectPrivate::connect(m_pTcpServer, &QTcpServer::newConnection,
                                     this, &QWebSocketServerPrivate::onNewConnection);
@@ -82,7 +82,7 @@ void QWebSocketServerPrivate::init()
             qFatal("Could not allocate memory for tcp server.");
     } else {
 #ifndef QT_NO_SSL
-        QSslServer *pSslServer = new QSslServer();
+        QSslServer *pSslServer = new QSslServer(q_ptr);
         m_pTcpServer = pSslServer;
         if (Q_LIKELY(m_pTcpServer)) {
             QObjectPrivate::connect(pSslServer, &QSslServer::newEncryptedConnection,
@@ -105,8 +105,6 @@ void QWebSocketServerPrivate::init()
  */
 QWebSocketServerPrivate::~QWebSocketServerPrivate()
 {
-    close(true);
-    m_pTcpServer->deleteLater();
 }
 
 /*!