title: Qt C++ QTcpServer not connecting to Threaded Socket
body: <p>I have worked through <code>C++ Qt 68 - QTcpServer using multiple threads</code> and followed his steps, but I can't seem to get the program to work correctly.<br />
  I am using Qt 6.3.0 and the only difference between VoidRealm's code and mine is that I am using the new <code>Signals and Slots</code> system.<br />
  My Code:</p>
  <pre class="lang-cpp prettyprint-override"><code>//myserver.h
  
  #ifndef MYSERVER_H
  #define MYSERVER_H
  
  #include &lt;QTcpServer&gt;
  #include &lt;QObject&gt;
  #include &lt;QDebug&gt;
  #include &quot;mythread.h&quot;
  
  class MyServer : public QTcpServer
  {
      Q_OBJECT
  public:
      explicit MyServer(QObject *parent = nullptr);
  
      void startServer();
  
  protected:
      void incomingConnection(int socketDescriptor);
  };
  
  #endif // MYSERVER_H
  </code></pre>
  <pre class="lang-cpp prettyprint-override"><code>//myserver.cpp
  #include &quot;myserver.h&quot;
  
  MyServer::MyServer(QObject *parent)
      : QTcpServer{parent}
  {
  }
  
  void MyServer::startServer()
  {
      if(!this-&gt;listen(QHostAddress::Any, 1234))
      {
          qDebug() &lt;&lt; &quot;Could not start Server!&quot;;
      } 
      else 
      {
          qDebug() &lt;&lt; &quot;Listening...&quot;;
      }
  }
  
  void MyServer::incomingConnection(int socketDescriptor)
  {
      qDebug() &lt;&lt; socketDescriptor &lt;&lt; &quot; Connectng...&quot;;
      MyThread *thread = new MyThread(socketDescriptor, this);
  
      connect(thread, &amp;QThread::finished, thread, &amp;QObject::deleteLater);
  
      thread-&gt;start();
  
  }
  </code></pre>
  <pre class="lang-cpp prettyprint-override"><code>//mythread.h
  
  #ifndef MYTHREAD_H
  #define MYTHREAD_H
  
  #include &lt;QThread&gt;
  #include &lt;QObject&gt;
  #include &lt;QTcpSocket&gt;
  #include &lt;QDebug&gt;
  
  class MyThread : public QThread
  {
      Q_OBJECT
  public:
      MyThread(int ID, QObject *parent = nullptr);
  
      void run();
      void readyRead();
      void disconnected();
  
  signals:
      void error(QTcpSocket::SocketError socketError);
  
  private:
      QTcpSocket *socket;
      int socketDescriptor;
  };
  
  #endif // MYTHREAD_H
  </code></pre>
  <pre class="lang-cpp prettyprint-override"><code>//mythread.cpp
  
  #include &quot;mythread.h&quot;
  
  MyThread::MyThread(int ID, QObject *parent)
      :QThread(parent)
  {
      this-&gt;socketDescriptor = ID;
  }
  
  void MyThread::run()
  {
      qDebug() &lt;&lt;socketDescriptor &lt;&lt; &quot; Starting Thread&quot;;
      socket = new QTcpSocket();
  
      if(!socket-&gt;setSocketDescriptor(this-&gt;socketDescriptor))
      {
          emit error(socket-&gt;error());
          return;
      }
  
      connect(socket, &amp;QIODevice::readyRead, this, &amp;MyThread::readyRead,Qt::DirectConnection);
      connect(socket, &amp;QTcpSocket::disconnected, this, &amp;MyThread::disconnected,Qt::DirectConnection);
  
      qDebug() &lt;&lt; socketDescriptor &lt;&lt; &quot; Client Connected!&quot;;
  
      exec();
  }
  
  void MyThread::readyRead()
  {
      QByteArray Data = socket-&gt;readAll();
  
      qDebug() &lt;&lt; socketDescriptor &lt;&lt; &quot; Data in: &quot; &lt;&lt; Data;
  
      socket-&gt;write(Data);
  }
  
  void MyThread::disconnected()
  {
      qDebug() &lt;&lt; socketDescriptor &lt;&lt; &quot; Disconnected&quot;;
  
      socket-&gt;deleteLater();
  
      quit();
  }
  
  </code></pre>
  <p>When Running this, I get the console saying <code>Listening...</code>, but when I then use command prompt and change it to telnet using <code>...&gt; telnet</code>, and then type <code>...&gt; open 127.0.0.1 1234</code>, all I am getting is:</p>
  <pre><code>Welcome to Microsoft Telnet Client
  
  Escape Character is 'CTRL+]'
  
  Microsoft Telnet&gt; open 127.0.0.1 1234
  Connecting To 127.0.0.1...
  </code></pre>
  <p>After which nothing happens. What exactly am I doing wrong?</p>