title: Qt connect function between slot and signal does not work into thread run function
body: <p>I wroute a server program and a client program by qt.
  client program create connection to local host port 60600 by tcp protocol and server program listen to that port.
  after creating new connection by client, server accept connection and send packets to client.
  In normal state, I create TCPClient class object and TCPServer class object in main function of client and server programs and it work properly.</p>
  
  <p>but i need to create objects into thread and create and start thread in main function.
  when i move code of creating client or server objects to run() function of Qthread it runs but server and clients does not work properly.</p>
  
  <p>connect() function in constructor of server and client classes return true but connection does not work and slot function does not call.</p>
  
  <p>can any help me?</p>
  
  <p>server code is here:</p>
  
  <p>main.cpp:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
  
      ......
  
      PgThread* MyThread = new PgThread( d );
      MyThread-&gt;start();
  
      ......
  
      return app.exec();
  }
  </code></pre>
  
  <p>PgThread.cpp</p>
  
  <pre><code>PgThread::PgThread( int packetsizein )
  {
      packetsize = packetsizein;
      //connect( this, SIGNAL(finished()), this, SLOT(finishedReq() ));
  
  }
  PgThread::~PgThread
  
  ()
  {
      delete server;
  }
  
  void PgThread::run()
  {
      server = new tcpserver(packetsize);
  
  }
  </code></pre>
  
  <p>tcpserver.cpp:</p>
  
  <pre><code>tcpserver::tcpserver(int packsize)
  {
      packetSize = packsize;
      server = new QTcpServer(this);
      server -&gt; listen( QHostAddress::Any,60600 );
      connect( server,SIGNAL(newConnection()),this,SLOT(newConnectionRequest()) );
  }
  
  void tcpserver::newConnectionRequest()//does not call when tcpserver object create in run comnmand of pgthread
  {
      i=i+1;
      QTcpSocket *clientConnection = server-&gt;nextPendingConnection();
      connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater()));
      QByteArray block;
      char c;
      c=(char)i;
      block.append(c);
      for (int k=1;k&lt;packetSize;k++)
          block.append('A');
      clientConnection-&gt;write(block);
      clientConnection-&gt;flush();
      qint64 current = QDateTime::currentMSecsSinceEpoch();
      if(forDebug)
          cout &lt;&lt; "start time: " &lt;&lt;current&lt;&lt;endl;
      else
          cout &lt;&lt; i &lt;&lt; "\n" &lt;&lt; current &lt;&lt; endl;
      clientConnection-&gt;disconnectFromHost();
  }
  </code></pre>