Hello,
I have to port some app from Qt3 to Qt4 and have problem with slot connected to readyRead signal. It just doesn get called at all. I thought it is because socket wrapper in app gets called from some thread without event loop. I've inherited this wrapper from QThread, moved socket to this thread as described here http://www.qtcentre.org/threads/2716...ain-event-loop, but it still doesn't work. I also tried to instantiate QTcpSocket in run(). Below is stripped version of socket wrapper:
Qt Code:
  1. class ClientSocket : public QThread
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. ClientSocket();
  7. ...
  8. public slots:
  9. void test();
  10.  
  11. private:
  12. QTcpSocket* m_socket;
  13. };
  14.  
  15. ClientSocket::ClientSocket() : QThread()
  16. ,m_socket(new QTcpSocket())
  17. {
  18. m_socket->moveToThread(this);
  19. connect(m_socket, SIGNAL(readyRead()), this, SLOT(test()));
  20. start();
  21. }
  22.  
  23. bool ClientSocket::connectToHost(QString host, int port)
  24. {
  25. if (port == 0) return false;
  26. m_socket->connectToHost(host, port);
  27. return m_socket->waitForConnected(1000);
  28. }
  29.  
  30. void ClientSocket::write(const char* Data,unsigned int nBytes)
  31. {
  32. if (m_socket && (m_socket->state() == QAbstractSocket::ConnectedState))
  33. {
  34. m_socket->write(Data);
  35. m_socket->flush();
  36. }
  37. }
  38.  
  39. void ClientSocket::test()
  40. {
  41. stop();
  42. }
  43.  
  44. void ClientSocket::run()
  45. {
  46. exec();
  47. }
To copy to clipboard, switch view to plain text mode 
At some place in some thread this class is instantiated in constructor like this:
Qt Code:
  1. SomeClass::SomeClass()
  2. : m_ClientSocket()
  3. {
  4. bool bConnected = m_ClientSocket.connectToHost("localhost", 1000);
  5. if (bConnected)
  6. {
  7. m_ClientSocket.write("rtst", 4);
  8. }
  9. }
To copy to clipboard, switch view to plain text mode 
I test it with echo server that writes received string back. But test() slot is never called. connect() with Qt::QueuedConnection didn't change anything.
have somebody any idea why it doesn't work?