Hello every one,

I am really grateful for such a wonderful support forum for QT. I could get most of my question answered till today except this one... Great going...

the basic functionality:
create a gui application and then create a thread that holds a tcpsocket connection and perform a tedious calculation on the data received on the Socket..

the tcp connection at which the data is received is LocalHost:3000


I created a basic QT GUI application and then at the press of a button; i would create a thread with the command...
Qt Code:
  1. mythread *txt = new mythread();
  2. txt->start();
To copy to clipboard, switch view to plain text mode 

the thread is defined with the following constructor...
mythread.h


Qt Code:
  1. class mythread : public QThread
  2. {
  3. Q_OBJECT
  4. public:
  5. mythread(QObject *parent = 0);
  6. void run();
  7. private :
  8. QTcpSocket socket;
  9. }
To copy to clipboard, switch view to plain text mode 



mythread.cpp



Qt Code:
  1. mythread::mythread(QObject *parent)
  2. : QThread(parent)
  3. {
  4. }
  5.  
  6. void mythread::run(){
  7.  
  8. qint64 maxlen = 128;
  9. socket.connectToHost(QHostAddress::LocalHost,3000);
  10. if (socket.waitForConnected(1000))
  11. qDebug("Connected!");
  12. char buffer[128];
  13. //QDataStream in(&socket);
  14. //in.setVersion(QDataStream::Qt_4_6);
  15. while(1){
  16. qint64 len = socket.readLine(buffer, maxlen);
  17.  
  18. if(len < 0){
  19. qDebug()<<"the break function";
  20. break;
  21. }
  22. qDebug()<<"The buffer is" <<buffer<<"and its size is "<<len;
  23. }
  24. }
To copy to clipboard, switch view to plain text mode 



After i run this, i always get the error saying that


QObject: Cannot create children for a parent that is in a different thread. (Parent is QTcpSocket(0x980df60), parent's thread is QThread(0x3d4ec8), current thread is mythread(0x980df58)
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QTcpSocket(0x980df60), parent's thread is QThread(0x3d4ec8), current thread is mythread(0x980df58)
Connected!
The buffer is and its size is 0
The buffer is and its size is 0
The buffer is and its size is 0
The buffer is and its size is 0
The buffer is and its size is 0
The buffer is and its size is 0
The buffer is and its size is 0
The buffer is and its size is 0
The buffer is and its size is 0
The buffer is and its size is 0



Could any one help me in this regard...

Thanking you

Rajesh Medampudi....